php - I'm trying to post form data from select inputs in Laravel. (What I have works if I use text boxes)
Get the solution ↓↓↓resources\views\weapons\index.blade.php (Has about eight of these all with unique names)
<select name="platform" class="form-control" id="platform" placeholder = "Platform" >
<option value="All">Platform</option>
<option value="PC">PC</option>
<option value="PS4">PS4</option>
<option value="Xbox">XBOX</option>
</select>
<form method="post" action="{{ route('weapons.store') }}" id="myForm">
wep.php
<?php
use Illuminate\Support\Facades\Route;
use app\Http\Controllers\WeaponsController;
Route::resource('weapons', 'WeaponsController');
WeaponsController.php (I wish I knew how to add additional functions to this? Any time I try I get undefined function.
public function store(Request $request)
{ echo htmlspecialchars(print_r($_POST, true));
//Weapon::create($request->all());
$request->get('platform');
echo $request;
The $_POST array contains this: Array ( [_token] => k6c6YQYaXVwqzDlsgCxyy5FckKs7Kgkn1IatV0oV [Cancel] => Delete [notes] => ) Cancel, Delete and notes are input other than select, but none of my eight or so select choices are received? This is the model: weapon.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class weapon extends Model
{
protected $fillable = [
'platform', 'username', 'player','level','prefix','weapon','primary','secondary','value','notes'
];
}
I'm very new to Laravel and MCV in general I've built what I have from repurposing this example: https://www.indeveloper.id/2020/01/tutorial-crud-laravel-6-menggunakan-orm.html?showComment=1592385889357 but I need to use select boxes not text boxes. I've been at this for days. A complete Method Route View & Controller working example would be AWESOME!!!
Answer
Solution:
your<form
starts afterselect
put<select> </select>
inside form then form values will be post
<form method="post" action="{{ route('weapons.store') }}" id="myForm">
<select name="platform" class="form-control" id="platform" placeholder = "Platform" >
<option value="All">Platform</option>
<option value="PC">PC</option>
<option value="PS4">PS4</option>
<option value="Xbox">XBOX</option>
</select>
//other fields
</form>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: object of class stdclass could not be converted to string
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.