Reputation: 431
I am learning the Laravel by building a job portal app. And I am coding for the company side to edit their post.
Now I could go to url, ex) http://localhost:8000/jobs/23/edit
. But on the screen shows me 404|not found
error message
for edit page, I created views/jobs/edit.blade.php.
Of course, data is clearly inserted in my job table.
I tried to clear all the cache and, executed following commands.
1. composer dump-autoload
2. php artisan clear-compiled
3. php artisan optimize
4. php artisan config:cache
web.php
Route::get('/jobs/{id}/edit', 'JobController@edit')->name('job.edit');
JobController.php
public function edit($id)
{
$jobs = Job::findOrFail($id);
return view('jobs.myjob',compact('jobs'));
}
my-job.blade.php I have an edit button and following code is a link it has.
{{route('job.edit',[$job->id])}}
My environment is Windows, XAMPP and local MySQL server.
Upvotes: 0
Views: 224
Reputation:
The problem is probably in the line return view('jobs.myjob',compact('jobs'));
in your JobController.php
, it returns the following view: resources/views/jobs/myjob.blade.php
(which probably doesn't exist).
try changing the line return view('jobs.myjob',compact('jobs'));
to return view('jobs.edit',compact('jobs'));
, after the change it refers to resources/views/jobs/edit.blade.php
and that should solve your problem.
Upvotes: 0
Reputation: 431
I finally could solve this problem.
I changed to a new route.
Route::get('/test-jobs/{id}/edit', 'JobController@edit')->name('test-job.edit');
I created new blade.php like this, views/test-jobs/edit.blade.php
I also changed JobController.php
public function edit($id){ $jobs = Job::findOrFail($id); return view('test-jobs.edit',compact('jobs')); }
And finally, my-job.blade.php which has an edit button like this.
<a href="{{route('test-jobs.edit',[$job->id])}}"><button class="btn btn-dark">Edit</button></a>
But still, I don't know why it worked.
And also, I think I need another solution. Because in this way, I needed to create another new folder in views.
So if someone knows another solution, please let me know. Thank you.
Upvotes: 0
Reputation: 13669
try this way :
<a href="{{route('job.edit',['id'=>$job->id])}}">Edit Job {{$job->id}}</a>
you can clear route cache by :
php artisan route:clear
update : run following command to clear cache
php artisan config:clear
php artisan cache:clear
Upvotes: 2