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 :
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
You should use your controllers and then reference the controller class in your route.
For example:
This is also how it is done in the Laravel docs.
You have to import the class first
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.