Laravel 8 Redirect Route With Query String
In this tutorial, we will tell you how to use the redirect route with the query string in laravel 8.
Why use a redirect route with another parameter or query string in laravel application.
sometimes we need to redirect with a success message or error message at that time we will use the redirect route with another parameter or query string in laravel application.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | <?php namespace App\Http\Controllers; use App\Models\Student; use Illuminate\Http\Request; class StudentController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { // $students = Student::all(); return view('student.list', compact('students','students')); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // return view('student.create'); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ 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 \App\Student $student * @return \Illuminate\Http\Response */ public function show(Student $student) { // return view('student.view',compact('student')); } /** * Show the form for editing the specified resource. * * @param \App\Student $student * @return \Illuminate\Http\Response */ public function edit(Student $student) { // return view('student.edit',compact('student')); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Student $student * @return \Illuminate\Http\Response */ 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 \App\Student $student * @return \Illuminate\Http\Response */ public function destroy(Student $student) { // $student->delete(); return redirect('/student')->with('success', 'Student deleted successfully'); } } ?> |
So here, we have used the redirect route with string parameter in studentController.php. such as store method, update method, and destroy method.
Read Also
Laravel 8 Stripe Payment Gateway Integrate Example
Laravel 8 Generate Dynamic XML Sitemap
Laravel 8 Elasticsearch Integration From Scratch With Example
Please follow and like us: