Reputation: 15
I use Laravel 5.2 a few day ago, and I've a problem! I hope, somebody can help me.
I want a special proceedings, so I don't use resource. My problem, the user's datas doesn't update in database, I try this a lots of ways, but nothing.
Here is my controller:
protected function edit($name)
{
return view('user.edit', array('user' => User::findByUsernameOrFail($name)));
}
protected function update($name, ProfileDataRequest $request)
{
$profile = User::findorfail($name);
$input = $request -> all();
$profile->update($input);
return redirect()->action('UserController@show');
}
My form:
{!! Form::model($user, ['method' => 'PATCH', 'action' => ['UserController@update', $user -> name ]]) !!}
{{ csrf_field() }}
{!! Form::label('sms', 'SMS: ') !!}
{!! Form::checkbox('sms', 1, false) !!}
{!! Form::label('name', 'Name: ') !!}
{!! Form::text('name') !!}
{!! Form::submit('Submit') !!}
{!! Form::close() !!}
My route:
Route::get('/user', 'UserController@index');
Route::get('/user/{name}', 'UserController@show');
Route::get('/user/{name}/edit', 'UserController@edit');
Route::patch('/user/{name}', 'UserController@update');
My request file:
class ProfileDataRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required',
'sms' => 'required',
];
}
}
If you have a more simple method, please write to me!
Upvotes: 0
Views: 83
Reputation: 1928
Your controller methods are protected
they should be public
to be accessible.
replace protected
to public
public function update(Request $request) {
//your code here
}
Upvotes: 1