In this tutorial learn how to pass value or variable from controller to view in laravel, Passing variable controller to view using with method, to pass variable in laravel.
web.php
Create controller CategoryController.php in controllerreturn view('category')->with('name',"passing value");
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class CategoryController extends Controller
{
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$name = "Nakiya";
return view('category')->with('name',$name);
}
}
create a view in views category.blade.php
Welcome To the Category! {{$name}}
Dependency Injection & Route Parameters
If your controller method is also expecting input from a route parameter you should list your route parameters after your other dependencies. For example, if your route is defined like so:
web.php
Run with php artisan serve and pass the variableRoute::get('/category', 'CategoryController@index')->name('category');
http://127.0.0.1:8000/category
No comments:
Post a Comment