Passing data to views from routes in Laravel

Today, We want to share with you Passing data to views from routes in Laravel.In this post we will show you , hear for Laravel passing data from view to controller we will give you demo and example for implement.In this post, we will learn about how to pass variable from view to route in laravel with an example.

Passing data to views from routes in Laravel

There are the Following The simple About Passing data to views from routes in Laravel Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel pass multiple arrays to view, so the some laravel pass data to view from controller for this example is following below.

More Details for Pakainfo Blog:Free Download Example – Pakainfo.com

Laravel ATTACHING DATA TO VIEW

Route::get('/', function(){
   return view('welcome',['name'=>'Pakainfo','age'=>3]); 
});

Laravel Hello {{$name}}

Your Age is {{$age}}

ATTACHING DATA USING WITH METHOD

Route::get('/', function(){
   return view('welcome')->with('name','Pakainfo'); 
});

USING COMPACT METHOD

//Welcome view
Route::get('/', function(){
    $name = 'Pakainfo';
    return view('welcome',compact('name')); 
});

//Data View
Route::get('/data', function(){
    $name = 'Pakainfo';
    $age = '28';
    return view('data',compact('name','age')); 
});

//Sending as List
Route::get('/listdata', function(){
    $tasks = [
        'Write Code',
        'Unit Test',
        'Deliver'  
    ];
    return view('listdata',compact('tasks')); 
});

simple Laravel Passing data from controller to view in Laravel

app/Http/Controllers/HomeController.php

middleware('auth');
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $flagstatus = "Normal";
        $status_list = DB::table('statuses')->whereNull('deleted_at')->pluck("name","id");
        return view('products.index',compact('status_list','flagstatus'));
    }
?>

resources/views/products/iundex.blade.php

@extends('layouts.default')
@section('title', 'Dashboard')

@section('content')
@endsection
Pakainfo
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 Passing data to views from routes in Laravel.
I would like to have feedback on my Pakainfo 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