laravel 7 redirect route with query string – onlinecode

laravel 7 redirect route with query string – onlinecode

In this post we will give you information about laravel 7 redirect route with query string – onlinecode. Hear we will give you detail about laravel 7 redirect route with query string – onlinecodeAnd how to use it also give you demo for it if it is necessary.

In this tutorial, we will tell you how to use the redirect route with the query string in laravel 7.

Why use redirect route with another parameter or query string in laravel application.

sometimes we need to redirect with success message or error message at that time we will use the redirect route with another parameter or query string in laravel application.

<?php

namespace AppHttpControllers;

use AppStudent;
use IlluminateHttpRequest;

class StudentController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return IlluminateHttpResponse
     */
    public function index()
    {
        //
        $students = Student::all();
        return view('student.list', compact('students','students'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return IlluminateHttpResponse
     */
    public function create()
    {
        //
        return view('student.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  IlluminateHttpRequest  $request
     * @return IlluminateHttpResponse
     */
    public function store(Request $request)
    {
        //
        $request->validate([
            'txtFirstName'=>'required',
            'txtLastName'=> 'required',
            'txtAddress' => 'required'
        ]);

        $student = new Student([
            'first_name' => $request->get('txtFirstName'),
            'last_name'=> $request->get('txtLastName'),
            'address'=> $request->get('txtAddress')
        ]);

        $student->save();
        return redirect('/student')->with('success', 'Student has been added');
    }

    /**
     * Display the specified resource.
     *
     * @param  AppStudent  $student
     * @return IlluminateHttpResponse
     */
    public function show(Student $student)
    {
        //
        return view('student.view',compact('student'));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  AppStudent  $student
     * @return IlluminateHttpResponse
     */
    public function edit(Student $student)
    {
        //
        return view('student.edit',compact('student'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  IlluminateHttpRequest  $request
     * @param  AppStudent  $student
     * @return IlluminateHttpResponse
     */
    public function update(Request $request,$id)
    {
        //

        $request->validate([
            'txtFirstName'=>'required',
            'txtLastName'=> 'required',
            'txtAddress' => 'required'
        ]);


        $student = Student::find($id);
        $student->first_name = $request->get('txtFirstName');
        $student->last_name = $request->get('txtLastName');
        $student->address = $request->get('txtAddress');

        $student->update();

        return redirect('/student')->with('success', 'Student updated successfully');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  AppStudent  $student
     * @return IlluminateHttpResponse
     */
    public function destroy(Student $student)
    {
        //
        $student->delete();
        return redirect('/student')->with('success', 'Student deleted successfully');
    }
}
?>

So here, we have used redirect route with string parameter in studentController.php. such as store method, update method, and destroy method.

Please follow and like us:

Hope this code and post will helped you for implement laravel 7 redirect route with query string – onlinecode. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

9  +  1  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US