0

I'm a beginner using this laravel framework. Currently i'm trying to understand the routing and controller of this framework.

I created a controller file using this command:

php artisan make:controller Admin/PostController

Of course the output of this is to create a controller file inside Admin folder. Inside of the PostController.php i wrote a code like this:

    public function create()
    {
      return view('admin.post.post');
    }

Also, in my web.php i have this code.

Route::get('/', function () {
return view('user.blog');
});

Route::get('posts',function(){
return view('user.posts');
})->name('posts');


Route::resource('admin/post','Admin\PostController');

The "admin" is a folder and the "post" is a folder too inside the "admin" and when you open the "post" folder you'll see the "post.blade.php" file. The other two route::get in my web.php are working fine. But the route:resource is not working.

When i tried to run this in my browser using this link:

localhost:8000/admin/post/create

The browser says: Sorry, the page you are looking for could not be found

Is there any problem with syntax or path structures?

Here's my post.blade.php

@extends('admin.layouts.app')


@section('main-content')
 this is just html codes..
 @endsection

Here's my php artisan route:list route list

Pablo
  • 1,357
  • 1
  • 11
  • 40
  • localhost:8000/admin/post/create it is a post request? is'nt it ? – Salman Zafar Jul 23 '18 at 02:27
  • I'm trying to follow this tutorial but it seems not working. I double checked my code but i dont see any flaws. @Salman Zafar https://www.youtube.com/watch?v=PMYSpg93wYU&index=8&list=PLe30vg_FG4OTELVqQgHaMaq2oELjpSWy_ – Pablo Jul 23 '18 at 02:28
  • can you post your blade file code as well – Salman Zafar Jul 23 '18 at 02:31
  • localhost:8000/admin/post/create when you hit this link. The browser should redirect me to the post.blade.php because i already stated in my code in PostController.php the "return view('admin.post.post');" – Pablo Jul 23 '18 at 02:31
  • php artisan route:list post the output in your question – Salman Zafar Jul 23 '18 at 02:33
  • I updated my post. Included the route list and codes for post.blade.php – Pablo Jul 23 '18 at 02:35
  • in your blade file after this
    add this line @csrf and then try again
    – Salman Zafar Jul 23 '18 at 02:46
  • hi, put Route::get('posts/create', function () { return view('admin.post.post'); }); above route:resource line and go to localhost:8000/posts/create and tell us what happens – ashish Jul 23 '18 at 02:54
  • Late reply sir, hello @ashish it works!! thankyou! but whats the meaning of this code sir? is this connected too to my PostController.php file ? – Pablo Jul 23 '18 at 02:59
  • It is not connected to your post controller file, i was trying to check if your view accessible or not. seems to be, there is some conflict on your route:resource – ashish Jul 23 '18 at 03:06
  • I think so.. But the only code added to my PostController only this: return view('admin.post.post'); inside the public function create. i'm sill trying to figure it out why the route::resource is not working – Pablo Jul 23 '18 at 03:14
  • i think you should try and see if the same code works if you arent using admin in Route::resource('admin/post','Admin\PostController'); see this works when you do administrator instead – ashish Jul 23 '18 at 03:20
  • i tested this codeRoute::resource('admin/post','Admin\PostController'); but this code isn't working as it connected to my PostController. But the one code you gave to me is working fine. – Pablo Jul 23 '18 at 03:25
  • The code i gave you before isnt using postcontroller at all. If you want to use PostController, you have to find a day to do it. BTW, i have tested your code in my computer and its working in my end. – ashish Jul 23 '18 at 03:28
  • I want to use postcontroller. If my code is working on your computer maybe the version of my laravel is the reason why not working here? Because there are times like i was trying to run my laravel using this code. php artisan serve but this code is not working on my computer but i tried this php -S localhost:8000 -t public/ it works – Pablo Jul 23 '18 at 03:35

1 Answers1

0

this because some time composer stuck, for that times you should stop serve and re generate autoload

1.stop your php artisan serve 2.enter this command

composer dumpautoload

3.run your php artisan serve

Abdi
  • 589
  • 5
  • 16