Reputation: 609
I'm trying to make a CRUD (which was working fine in a simple blade) in a new template but it is not showing any page of crud and says not found. If I type: php artisan route:list
then it says:
Class App\Http\Controllers\PostsController does not exist
I'm following this tutorial and my folder structure is https://ibb.co/db4WQ8R
Controller
class CrudsController extends Controller
{
public function index()
{
$data = Post::latest()->paginate(5);
return view('adminhome', compact('data'))
->with('i', (request()->input('page', 1) - 1) * 5);
}
public function create()
{
return view('create');
}
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'image' => 'required|image'
]);
$image = $request->file('image');
$new_name = rand().'.'.$image->getClientOriginalExtension();
$image->move(public_path('images'), $new_name);
$form_data = array(
'name' => $request->name,
'image' => $new_name
);
Crud::create($form_data);
return redirect('post')->with('success', 'Data Added successfully.');
}
}
Routes
Route::group(['middleware' => ['auth']], function () {
Route::get('/home', function () {
if (Auth::user()->admin === 0) {
return view('home');
}
return view('adminhome');
});
Route::resource('post', 'PostsController');
});
How can I solve it?
Upvotes: 1
Views: 269
Reputation: 3318
In your controller rename Cruds
class PostsController extends Controller
{
Upvotes: 3