0

The following is a sample of an array inside an array :

array:2 [▼
  0 => {#338 ▼
    +"id": 25
    +"created_at": "2019-10-18 11:13:17"
    +"updated_at": "2019-10-18 11:13:17"
    +"title": "question"
    +"body": """
       \r\n
         aasasas
      """
    +"ttype": 0
    +"cat": 0
    +"a_id": 25
    +"tag": ""
    +"appr": 0
    +"user_id": 6
    +"comment_id": 0
    +"parent_id": null
    +"ppoints": null
    +"status": 0
    +"arank": 1
    +"qatype": 1
    +"country": "Egypt"
    +"wwide": 0
  }

Is there a way to display the required array values based on a condition inside the blade ? For example, the following will show the title in the view : {{$updt_11->title}}. Can I display the title if the id=25 for example ?

A wrong example for demonstration:

{{ $updt_11->where('id',25)->select('title')->first()->title}}
1

2 Answers 2

2

Inside blade file, you can be able to use if a condition like:

@if($updt_11->id == '25')
    {{ $updt_11->title }}
@endif

Try it.

Sign up to request clarification or add additional context in comments.

Comments

1

Basically if you want to use Model output in your blade, you can do something like:

{{ \App\Models\MyModel::where('id',25)->first()->title}} 
  • If you don't have a Models folder in your laravel project then your path will be : \App\MyModel

Your Model should look like (just an example) :

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class MyModel extends Model
{

     protected $table = 'my_table';

     protected $guarded = [];

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.