0

Am new to Laravel and am using Laravel 8.83.5. I created a new controller called Posts PostsController using php artisan and I also created a new directory called posts in the layouts directory but when I try accessing that file using http://127.0.0.1:8000/p I get an error that TIlluminate\Contracts\Container\BindingResolutionException Target class [PostsController] does not exist.

here is my web.php file

<?php
// use Illuminate\Support\Facades\Auth;
// use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;
// use Illuminate\Routing\Route;
use Illuminate\Support\Facades\Route;
Route::get('/',function(){
return view('welcome');
});

Auth::routes();

Route::get('/p','PostsController@create');

Route::get('/profile/{user}','ProfilesController@index')->name('profile.show');

here is the file called create.blade.php i want to display when I run http://127.0.0.1:8000/p

@extends('layouts.app')

@section('content')
@endsection

and here is my postsController file <?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class PostsController extends Controller
{
public function create(){
    return view('posts.create');
}
}
kato james
  • 17
  • 5

1 Answers1

1
 <?php 
    //in web.php  namespace your Posts Controller
    use App\Http\Controllers\PostsController;
    
   Route::get('/posts',[PostsController::class, 'create'])->name('create');

try this out if works

srijan lama
  • 570
  • 6
  • 12