添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm using in controller:

$data = '{"pr":{"code":"1"},"ac":[[{"icon":"web","action":"link","url":"asd"}]]}'
$newData = json_decode($data);

And i send it to the view as array: 'data' => $newData And when i try to use $data into the view, it give me that error

Tried already to use $data->ac OR $data['ac'] but still the same... Some help, please?

json_decode returns an object by default. use $newData = json_decode($data,TRUE); for an array – user6763587 Apr 4, 2017 at 21:27

When you use a blade echo {{ $data }} it will automatically escape the output. It can only escape strings. In your data $data->ac is an array and $data is an object, neither of which can be echoed as is. You need to be more specific of how the data should be outputted. What exactly that looks like entirely depends on what you're trying to accomplish. For example to display the link you would need to do {{ $data->ac[0][0]['url'] }} (not sure why you have two nested arrays but I'm just following your data structure).

@foreach($data->ac['0'] as $link)
    <a href="{{ $link['url'] }}">This is a link</a>
@endforeach
                I had this because $errors->get() was returning an array. Switching to $errors->first() fixed this.
– brad
                Oct 13, 2018 at 14:30

if you real intention is to send the full array from the html to the controller, you can use the following code:

from the blade.php:

 <input type="hidden" name="quotation" value="{{ json_encode($quotation,TRUE)}}"> 

in controller

    public function Get(Request $req) {
    $quotation = array('quotation' => json_decode($req->quotation));
    return view('quotation')->with('quotation',json_decode($req->quotation))

You could use serialize

<input type="hidden" name="quotation[]" value="{{serialize($quotation)}}">

But best way in this case use the json_encode method in your blade and json_decode in controller.

Try use in your collection the json_encode().

https://www.php.net/manual/pt_BR/function.json-encode.php

public static function getTeamMemberInto($user_id){
    $team = DB::table('members_team')
                ->join('teams', 'teams.id', '=', 'members_team.teams_id')
                ->join('employees', 'employees.id', '=', 'teams.leader_employees_id')
                ->where('members_team.employees_id', '=', $user_id)
                ->select('*')->first();
    // dd($team);
    if($team){
        return json_encode($team, true);
    }else{
        return false;