I'm still exploring Laravel 8 but I have a problem with my controller's store() method 'not defined.'
InvalidArgumentException Action PostsController@store not defined. (View: D:\Server\htdocs\app\resources\views\posts\create.blade.php)
I believe I have actually defined it and I used a resources route.
Route
Route::resource('posts', PostsController::class);
Blade
@extends('layouts.app')
@section('content')
<h1>Create Post</h1>
{!! Form::open(['action' => 'PostsController@store', 'method' => 'POST']) !!}
<div class="form-group">
{{Form::label('title', 'Title')}}
{{Form::label('title', ['class' => 'form-control','placeholder' =>'Title'])}}
</div>
<div class="form-group">
{{Form::label('body', 'Body')}}
{{Form::textarea('body', ['class' => 'form-control','placeholder' =>'Body'])}}
</div>
{{Form::submit('Submit',['class' =>'btn btn-primary'])}}
{!! Form::close() !!}
@endsection
Controller
class PostsController extends Controller
{
public function create()
{
return view('posts.create');
}
public function store(Request $request)
{
$this->validate($request, [
'title' => 'required',
'body' => 'required'
]);
return 143;
}
}
Go into your RouteServiceProvider
and set the $namespace
property to App\Http\Controllers
if you want there to be a namespace prefix added when generating URLs for actions.
Otherwise you should be referring to your Controllers by their Fully Qualified Class Name (FQCN).
['action' => 'App\Http\Controllers\PostsController@store', ...]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With