Laravel Multiple middleware from controller in constructor

Today, We want to share with you Laravel Multiple middleware from controller in constructor.In this post we will show you Laravel Pass middleware parameters as array, hear for Laravel Multiple middleware on routing group we will give you demo and example for implement.In this post, we will learn about Laravel Passing parameters to middleware handlers with an example.

Laravel Multiple middleware from controller in constructor

There are the Following The simple About Laravel Multiple middleware from controller in constructor Full Information With Example and source code.

As I will cover this Post with live Working example to develop How to create middleware with parameters in Laravel 5?, so the Get Laravel Route Parameters in Middleware for this example is following below.

call middleware in controller laravel

laravel multiple middleware controller

Include this middleware

    public function __construct()
    {
        $this->middleware('member-list', ['only' => ['methodname1']]);
        $this->middleware('member-create', ['only' => ['methodname1','methodname2','methodname3']]);


        $this->middleware('member-update', ['only' => ['methodname1','methodname4','methodname5']]);
        $this->middleware('member-delete', ['only' => ['methodname1','methodname6']]);
    }

Laravel middleware in controller

Laravel call middleware from controller with construct

middleware('member-list', ['only' => ['index']]);
        $this->middleware('member-create', ['only' => ['index','create','store']]);


        $this->middleware('member-update', ['only' => ['index','edit','update']]);
        $this->middleware('member-delete', ['only' => ['index','delete']]);
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $members = Member::latest()->paginate(5);

        return view('members.index',compact('members'))
            ->with('i', (request()->input('page', 1) - 1) * 5);
    }
    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('members.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $request->validate([
            'name' => 'required',
            'detail' => 'required',
        ]);

        Member::create($request->all());

        return redirect()->route('members.index')
                        ->with('success','Member created successfully.');
    }
    /**
     * Display the specified resource.
     *
     * @param  \App\Member  $member
     * @return \Illuminate\Http\Response
     */
    public function show(Member $member)
    {
        return view('members.show',compact('member'));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Member  $member
     * @return \Illuminate\Http\Response
     */
    public function edit(Member $member)
    {
        return view('members.edit',compact('member'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Member  $member
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Member $member)
    {
        $request->validate([
            'name' => 'required',
            'detail' => 'required',
        ]);

        $member->update($request->all());

        return redirect()->route('members.index')
                        ->with('success','Member updated successfully');
    }
    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Member  $member
     * @return \Illuminate\Http\Response
     */
    public function destroy(Member $member)
    {
        $member->delete();

        return redirect()->route('members.index')
                        ->with('success','Member deleted successfully');
    }
}
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel Multiple middleware from controller in constructor.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment