2

I have the following in my web.php:

Route::resource('/job', 'JobController');

Linked to the controller, I have the usual CRUD methods, and some work so for example going to joben.app/job/1:

public function show(Job $job)
{
    //
    dd($job);
}

However, whenever I navigate to job.app/job I get a 404 error, and the same whenever I post to job.app/job

The code worked fine before and I haven't changed anything, I've attempted reinstalling Valet and also using Artisans own dev server to view and post to the pages and still have the same result

Where can I start looking?

Edit: Here is my route list for the Job controller (sorry for formatting)

| | GET|HEAD | job | job.index | App\Http\Controllers\JobController@index
| | POST | job | job.store | App\Http\Controllers\JobController@store | web |

| | GET|HEAD | job/create | job.create | App\Http\Controllers\JobController@create | web |

| | PUT|PATCH | job/{job} | job.update | App\Http\Controllers\JobController@update | web |

| | DELETE | job/{job} | job.destroy | App\Http\Controllers\JobController@destroy | web |

| | GET|HEAD | job/{job} | job.show | App\Http\Controllers\JobController@show | web |

| | GET|HEAD | job/{job}/edit | job.edit | App\Http\Controllers\JobController@edit | web |

and here is the controller code - http://codepad.org/vgot10GN

UPDATE AND SOLUTION:

Ok so this was a pretty unique problem, but it might be happening to you.

I was storing images in public folder - as a test for file uploads under a directory named job. Naturally, as the NGINX root for the files is the public folder, when posting to /job NGINX first assumed to go to the folder named job in the public folder.

Which in this instance was just a folder containing an image.

So after deleting this folder and reattempting it then worked.

Community
  • 1
  • 1
iLC
  • 347
  • 9
  • 22

2 Answers2

2

When you go to /job URL, Laravel will try to execute the JobController@index method.

To understand what exactly routes Route::resource generates, run this command:

php artisan route:list
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
  • @iLC please show the `recruiter` middleware. Also, if any other middleware is applied to the route, please show it as well. – Alexey Mezenin Jan 08 '18 at 06:41
  • ` public function handle($request, Closure $next) { if (\Auth::user()->role->name != 'recruiter') { return redirect('profile'); } return $next($request); } ` – iLC Jan 08 '18 at 06:42
  • @iLC do you apply any other middleware to the route in your `web.php`? Please show results for `php artisan route:list` for the `/job` URI. – Alexey Mezenin Jan 08 '18 at 06:43
  • added it in the question - i have no other middleware in the `web.php` – iLC Jan 08 '18 at 13:40
  • @iLC the code looks fine including the controller, routes etc. Maybe you use cache or something? – Alexey Mezenin Jan 08 '18 at 14:29
0

Check if your job.app is accessible, and if so, your pseudostatic is not configured. Please provide your server is apache or nginx.

  • yeah i can navigate to other pages and even some methods in the job controller, just not the index or the store http://codepad.org/vgot10GN – iLC Jan 08 '18 at 06:41