I send file from my html form and dump my file in controller. Dump result return correct result with file name.
dump($request->file);
But if I check for true or false then var_dump() return false.
var_dump($request->hasFile('file'));
That's because $request->file is a string and not instance of Illuminate\Http\UploadedFile.
You should use ->hasFile() only with files.
I'm just adding another thing.
When you don't add enctype="multipart/form-data" inside your form then you will get also this types of problem.
<form action="{{ route('store') }}" method="POST" enctype="multipart/form-data">
Or using form helper 'file' => true,
{!! Form::open(['route' => ['store'], 'file' => true]) !!}
I think this will help someone.
Related
I have a form and I'm trying to pass null value into the $dev-id parameter but it doesnt work, instead ti will replace the dev id parameter with the $id as shown in my code at the bottom,
The reason i needed it to be null because I'm using this function for 2 different page but one of the page doesn't have $dev_id. any help is appreciated
HTML:
<form method="post"
action="{{ route('admin.developers.admins.edit.post',['admin' => $admin, 'dev_id' => null, 'id' => $id]) }}" autocomplete="off" novalidate>
web.php :
Route::post('developers/{dev_id?}/admins/{id}/edit', 'Admin\DeveloperAdminController#postEditDeveloperAdmin')->name('admin.developers.admins.edit.post')->where(['dev_id' => '[0-9]+', 'id' => '[0-9]+']);
You can pass those parametres in the form of hidden input and in controller use request to get those values
Add these to yur form
<input type="hidden" value="anything" name="dev_id">
Instead you are using vue use `v-model` instead of name and value
Now modify your form like this
<form method="post"
action="{{ route('admin.developers.admins.edit.post',['admin' => $admin,'id' => $id]) }}" autocomplete="off" novalidate>
Now you are access that using $request object in your logic and check if the value is null or not
I can`t update my table. Maybe you can see where is problem.
Edit works fine. It brings value to the fields. If i erase {{ method_field('PUT') }} it saves values normally, but i need to UPDATE
It`s my UPDATE controller
public function update(Request $request, Radar $radar)
{
Radar::update([
'date' => $request->input('date'),
'number' => $request->input('number'),
'distance' => $request->input('distance'),
'time' => $request->input('time'),
]);
return redirect('/radars');
}
Thats how my view looks like:
<form action="{{ url('/radars')}}" method="post" >
{{ method_field('PUT') }}
{{ csrf_field() }}
Routes:
Route::put('radars/{radar}', 'RadarsController#update');
Error:
MethodNotAllowedHttpException
No message
Thank you for help.
You need to specify ID:
{{ url('/radars/') . $radar->id }}
Also, you need to use object and not just a model class. Something like:
public function update(Request $request, Radar $radar)
{
$radar->update($request->all());
return redirect('/radars');
}
Illuminate\Support\Facades\Request
Radar::update(Request::all());
Looking at it, I think it should be like the below:
<form action="{{ url('/radars/' . $radar->id )}}" method="post" >
If you look, you're posting to /radars but your route is radars/{driver}
You need to add where statement to tell which record to update and dont
Radar::where('id',$id)->update([
'date' => $request->input('date'),
'number' => $request->input('number'),
'distance' => $request->input('distance'),
'time' => $request->input('time'),
]);
return redirect('/radars');
If you are using resource route, then in your form, you need to change action from:
url('/radars')
to
route('radars.update', $radar)
and keep the following:
{{ method_field('PUT') }}
I have this in my form in the viewpage.php:
<form action="{{ route('test.route'), ['id' => $params_id] }}" method="POST" >
And this in the route.php:
Route::post('/testing/{{id}}',[
'uses' => 'TestController#testMethod',
'as' => 'test.route'
]);
And this is my TestController:
public function avaliarSubordinor(Request $request, $uid){
return $uid;
}
I get an error which says 'Missing required parameters for[Route: test.route] [URI: testing/{{id}}]. Essentially What i want is to pass a variable to my controller using a route with a parameter when form is submitted..
I dont know if I am doing this properlly..if anyone can help me or point me to an example so i can understand what I am doing wrong..
Laravel 5.2 Missing required parameters for [Route: user.profile] [URI: user/{nickname}/profile]
Using the above link I found a solution.. I changed:
<form action="{{ route('test.route'), ['id' => $params_id] }}" method="POST" >
to
<form action="{{ route('test.route', [$params_id]) }}" method="GET" >
and this:
Route::post('/testing/{{id}}',[
'uses' => 'TestController#testMethod',
'as' => 'test.route'
]);
to
Route::get('/testing/{id}',[
'uses' => 'TestController#testMethod',
'as' => 'test.route'
]);
and for reading value :
if ($request->id) {
}
And It works! But I wonder if anyone else can get a POST version working, or is GET the only way? I dont really know much about GET/POST request, only that it's used in forms and ajax.. Would really like to learn more about HTTP GET/POST, if anyone has anything to add please share!! thanks! Hope this answer will help someone!
For me this worked pretty well.
{{ Form::open(array('route' => array('user.show', $user->id))) }}
with class name
{{ Form::open(array('route' => array('user.show', $user->id), 'class' => 'section-top')) }}
Although it's an old post hopefully it will help others in future.
For me in Laravel 5.8 the POST method just worked fine.
HTML form:
<form method="POST" role="form" action="{{route('store_changed_role', [$user_id, $division_id])}}">
Route:
Route::post('/sotre_changed_role/{user_id}/{division_id}', 'Admin\UserController#store_changed_role')->name('store_changed_role');
I'm implementing bootstrap-slider in my CRUD, I have implemented it successfully in Create, the problem is when I try to edit it,
I want to get the current value from the Model. Idk how to do this.
This is for PATCH.
<div class="form-group">
<h3 class='box-title text-info'>Percentage</h3>
{!! Form::input('text','percentage',null,['id'=>'ex8', 'data-slider-id'=>'ex1Slider', 'data-slider-min'=>'0', 'data-slider-max'=>'100', 'data-slider-step'=>'5', 'data-slider-value'=>'50']) !!}
</div>
In your form instead of creating a new form. You will bind the form to the model.
{!! Form::model('modelname', [options here] !!}
All the fields will math the model's property values.
Edit
Here is an example
You must used something like this to create a EDIT FORM
{{ Form::model($smartphones, ['method' => 'PATCH', 'url' => 'smartphones/'.$smartphones->id]) }}
You get by using $(your_model)['inputID']...You can use in "data-slider-value"... Something like this
{{ Form::input('text','mem_ram', null, ['id' => 'mem_ram', 'data-slider-value'=>$smartphones['mem_ram']]) }}
I got a weird behaviour with the 'old value' feature from FormBuilder in Laravel 5.1.
On my blade template I use a simple text input:
{!! Form::open([ 'url' => route('album-photo'), 'method' => 'POST' ]) !!}
{!! Form::text('album_id', $album_id) !!}
{!! Form::close() !!}
On my controller I show the view:
$album_id = 1;
return view( $name_view, compact( 'album_id' ) );
The problem is that, even though I change the album_id value on my controller, the form builder on my view will keep printing the first value.
While if I use the normal html tag:
<input type="text" name="album_id" value="{{ $album_id }}" />
it will print the updated value.
So it looks like the FormBuilder class is getting the value from the old session and it can't manage the refreshing of the value.
Is there a way to fix it and keep using the FormBuilder methods instead of plain html?