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.

Another must read:  PHP Image Resize Script Example

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]); 
});

<h1>Laravel Hello {{$name}}</h1>
<p>Your Age is {{$age}}</p>

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

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

Another must read:  Stripe Refund Api Tutorial Example From Scratch

app/Http/Controllers/HomeController.php

<?php

use App\Products;
use DB;
use Illuminate\Http\Request;

class HomeController extends Controller
{
    public function __construct()
    {
        $this->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')
<div class="filter-bx">
    <div class="row">
        <div class="col-lg-3 col-sm-6">
            <div class="form-group">
                <label>Filter By({{$flagstatus}})</label>
                <select id="statusFilter" name="search_group_filter" class="form-control">
                    <option value="0">All Status</option>
                    @foreach ($status_list as $cat => $value)
                        <option value="{{ $cat }}"> {{ $value }}</option>
                    @endforeach
                </select>
            </div>
        </div>
    </div>
</div>
@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.

Another must read:  laravel Views share Variable multiple to controller