Laravel 6 Beginner - e4 - Pass Data to View

preview_player
Показать описание
In most cases, views are going to need some data. By the end of this episode you will know how to pass data to your views in 2 different methods and how to echo them out in a view using Blade.

DigitalOcean Referral

About This Course

If you have been looking to learn Laravel, there hasn't been a better time. The framework reached an important point in its life, with the release of Laravel 6. There has never been more demand for Laravel developers than now. In this series, we are going to get you started in your path to becoming a Laravel Artisan. Let's get right to it!
Рекомендации по теме
Комментарии
Автор

Thanks for making this Laravel tutorial. You make learning Laravel easy.

chonyou
Автор

In my case, sending value to view, worked like this

Route::get('/hello', function () {
$variable = 'Hi!! i am new in laravel';
return view('subviews.hello', ['data'=>$variable]);
});

jayantrawat
Автор

I ran into this issue when I pass the data
syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ', ' or ')'
any ideas ?

Tubee
Автор

This is perfect code for sending data..

Route::get('demo', function(){
$variable="hello from view demo 0";
$variable1="hello from view demo 1";
$variable2="hello from view demo 2";

return view('form', compact(['variable', 'variable1', 'variable2']));
});


in view you can access as below

<p>{{ $variable }}</p>
<p>{{ $variable1 }}
<p>{{ $variable2 }}</p>

himanshuparmar
Автор

Its throwing error

syntax error, unexpected ':', expecting ')'

Route::get('/', function () {
return view('welcome');
});

Route::get('/hello', function () {
$variable = "some string";
return view('hello', data: [
'somedata' => $variable,
]);
});

I tried this in laravel 6 and my php version is 7.4.0

vinitkadkol
Автор

Hello!! I have watched and Practiced with Your Series. It was very Helpful. but in the questionnaire project please I want to know how I can also delete a questionnaire the questions as well as the answers from the database

ndukelex
Автор

return view('layout.about', compact('anything'));

anonymore
Автор

When you think you're done, you can start all over😉
{{ $var }} = echo as string.
{!! $var !!} = render as html.

Stoney_Eagle
Автор

When using "compact" I got this error "compact() expects at least 1 argument, 0 given" maybe because I'm using laravel 8?

Edit:
If you are using laravel 8, when using compact got to use the 3 arguments: compact('view1', 'view2', 'view3');
I made 2 more variables named $view2 and $view3 with value set to null.

AlJapairai
Автор

Man, can we expect to see series on Laravel Advanced in future? Or are they over?

vqpepxk
Автор

Those tips at 1:06 "data" and "view". Would you know if there is an extension for that on VScode?

Ghaleon
Автор

that method hints like "varname", "view", "data" are a little confusing for learning purposes.

JohnSmith-zlrz
Автор

As of now in Laraval you can leave away the “view: “ and “data: “. And the compact() code in the video doesn’t exactly work, to make it work I did:

“compact ([‘coolString’]));” instead of “data: compact( varname: ‘coolString’));

aeronautisch
Автор

return view(view: 'hello', data:['data' => $data]); doesnt work. return view('hello', ['data' => $data]); this one does

tinhtoozaw