skip to Main Content

I currently developing Laravel application, since I use 2 different laptop and OS (Windows & Macbook), I realized that everytime I swicth PC, I have to changes the route in file web.php, just to make my app running well.

Why there is a difference of writing Laravel’s route between Windows & Mac OS, can I make the writing just same?so I don’t need to modify the script everytime I switched PC.

Here is the working route on Windows :

Route::get('/movies', 'MovieController@index');
Route::get('/movies/create', 'MovieController@create');
Route::get('/movies/edit/{id}', 'MovieController@edit');
Route::post('/movies/insert', 'MovieController@store');
Route::post('/movies/update', 'MovieController@update');
Route::get('/movies/delete/{id}', 'MovieController@destroy');

And here is the working route on my Macbook :

Route::get('/movies', 'AppHttpControllersMovieController@index');
Route::get('/movies/create', 'AppHttpControllersMovieController@create');
Route::get('/movies/edit/{id}', 'AppHttpControllersMovieController@edit');
Route::post('/movies/insert', 'AppHttpControllersMovieController@store');
Route::post('/movies/update', 'AppHttpControllersMovieController@update');
Route::get('/movies/delete/{id}', 'AppHttpControllersMovieController@destroy');

And this is the error displayed if I tried to run my app with the not worked one :

enter image description here

Here is another specification that maybe could help you to analyze :

  • PHP Version 8.1.10
  • Composer Version 2.5.1
  • On Windows I use XAMPP
  • On Macbook I use Nginx

Is there any things that I need to change or adjust to make my route working well in both Windows and Mac OS?

Please help and please let me know if you need any further information.

Thank you.

2

Answers


  1. You should use your controllers and then reference the controller class in your route.

    For example:

    <?php
    
    use AppHttpControllersMovieController;
    
    Route::get('/movies', [MovieController::class, 'index']);
    

    This is also how it is done in the Laravel docs.

    Login or Signup to reply.
  2. You have to import the class first

    <?php
    
    use AppHttpControllersAPIFrontendBlogController;
    use AppHttpControllersAPIFrontendCategoryController;
    use AppHttpControllersAPIRegisterController;
    use IlluminateHttpRequest;
    use IlluminateSupportFacadesRoute;
    
    /*
    |--------------------------------------------------------------------------
    | API Routes
    |--------------------------------------------------------------------------
    |
    | Here is where you can register API routes for your application. These
    | routes are loaded by the RouteServiceProvider within a group which
    | is assigned the "api" middleware group. Enjoy building your API!
    |
    */
    
    Route::controller(RegisterController::class)->group(function(){
        Route::post('register', 'register');
        Route::post('login', 'login');
        Route::get('test', 'test');
    });
    

    it’s a demo but if you see closely you will understand this. there are some extension for this to auto-import classes for vs code laravel-blade-snepate something like this or you can search youtube auto import laravel classes in your_code_editor_name.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search