jeudi 27 juin 2019

reuse controller / model in laravel

I want to reuse my code so I'm not repeating me self. I have made PostController and Post model. Now I want to create admin view page where I can CRUD my posts. Problem is here how to reuse Postcontroller to my admin view ?

to mentioned I'm new to laravel


use Illuminate\Http\Request;

use App\Post;

class PostsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $posts = Post::all();

        return view('posts.post', compact('posts'));
    } ...


namespace App\Http\Controllers;

use App\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\PostsController;

class AdminController extends PostsController
{

    public function index()
    {
        $posts = Post::all();

        return view('admin.index', compact('posts'));
    }

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire