79713542

Date: 2025-07-24 14:35:04
Score: 0.5
Natty:
Report link

✅ 1. Passing Multiple Variables from Controller

In your controller, you can pass multiple variables using:

return view('your_view_name', [

'name' =\> 'Khushali',

'age' =\> 24,

'city' =\> 'Rajkot'

]);

Or using compact()

$name = 'Khushali';

$age = 24;

$city = 'Rajkot';

return view('your_view_name', compact('name', 'age', 'city'));

---

✅ 2. Accessing Multiple Variables in Blade

In your Blade file (your_view_name.blade.php), you can directly access those variables:

<p>Name: {{ $name }}</p>

<p>Age: {{ $age }}</p>

<p>City: {{ $city }}</p>

---

✅ 3. Using Loops or Arrays

If you pass an array or collection:

return view('your_view_name', [

'users' =\> \[

    \['name' =\> 'Amit', 'age' =\> 30\],

    \['name' =\> 'Khushali', 'age' =\> 24\]

\]

]);

In Blade:

@foreach ($users as $user)

\<p\>{{ $user\['name'\] }} is {{ $user\['age'\] }} years old.\</p\>

@endforeach

---

✅ 4. Using @isset or @if

To check if a variable is set before using:

@isset($city)

\<p\>City: {{ $city }}\</p\>

@endisset

@if(isset($name))

\<p\>Hello, {{ $name }}\</p\>

@endif

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @foreach
  • User mentioned (0): @isset
  • Low reputation (1):
Posted by: Khushali Vasoya