ErrorException array_merge (): Argument # 2 is not an array (View: C: \ wamp64 \ www \ MYPROJECT \ resources \ views \ news \ index.blade.php)

0

I'm trying to show the elements of a database in Laravel and I get this error

ErrorException array_merge(): Argument #2 is not an array (View: C:\wamp64\www\MYPROJECT\resources\views\news\index.blade.php)

I did not find services.json and I already did composer update

The view is receiving the data because I printed it with dd('$variable') and if it comes out, but somehow it gets damaged when I put the table:

@extends('layout.master')

@section('content')

<h1>News List</h1>
<p class="lead">Here's a list of all your tasks. <a href="http://localhost:8000/news/create">Add a new one?</a></p>

<table class="table table-striped">
    <thead>
        <th>Title</th>
        <th>Article</th>
        <th>Image</th>
        <th width="280px">Options</th>
    </thead>

    <tbody>
        @foreach($news as $info)
        <tr>
            <td>{{$info->title }}</td>
            <td>{{$info->article}}</td>
            <td>{{$info->image}}</td>
            <td><a href="{{ view('news.show', $info->id) }}" class="btn btn-info">View Task</a>
        <a href="{{ view('news.edit', $info->id) }}" class="btn btn-primary">Edit Task</a></td>
        </tr>
        @endforeach

    </tbody>
</table>

@endsection 

Only removing that part disappears the error, but I need to list what is stored in the database.

    
asked by Bella 21.12.2017 в 13:16
source

1 answer

1

The view() in laravel method is a global helper to return one of the views stored in resources/views/

If what we are looking for is to obtain the url of a route we should use one of the following helpers:

action ()

$url = action('AlgunController@metodo', $parametros);

action() returns a url for a method of a controller.

route ()

$url = route('alias.ruta', $parametros);

route() returns a url from the alias given to a route.

url ()

$url = url('foo/bar', $parametros = [], $secure = null);

url() returns a complete url from a relative path.

secure_url ()

$url = secure_url('foo/bar', $parameters = []);

Same as above but using https by default.

For js files, images, etc ... laravel also provides a pair of helpers

asset ()

$url = asset('foto.jpg');

Returns the url for the file foto.jpg located in the directory public/asset/

Documentation: link

Therefore and starting from the previous information. Instead of using

{{ view('news.edit', $info->id) }}

You should use

{{ route('news.edit', $info->id) }}
    
answered by 22.12.2017 / 13:21
source