This is my first post on stackoverflow :)
I am new to Laravel and tried to display an array into a grid.
I choosed zofe/rapyd-laravel Datagrid, but even if it seems simple I cannot get it to display..
Here is my code :
public function index()
{
$reader = Reader::createFromPath('../uploads/pcl.csv');
$reader->setDelimiter(";");
$data = $reader->fetchAll();
//->toHTML('table-csv-data with-header');
//dd($data);
$headers = $reader->fetchOne();
//dd($headers);
$dataset = DataSet::source($data)->getSet();
//dd($dataset);
$grid = DataGrid::source($dataset);
//dd($grid);
return view('welcome',$grid);
and here is the 'welcome' blade file :
<html>
<head>
<title>Laravel</title>
<link href='//fonts.googleapis.com/css?family=Lato:100' rel='stylesheet' type='text/css'>
<!-- rapyd -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
{!! Rapyd::head() !!}
<!-- rapyd -->
</head>
</head>
<body>
<hr>
<p>
{{ $grid }}
</p>
</body>
</html>
The pcl.csv :
"nom";"prenom"
"B";"Alain"
"F";"Bruno"
"D";"Fabrice"
In the index function, all the dd commands display correct datas, but when I launch the serve command, I get this error :
[2015-06-03 15:22:43] local.ERROR: exception 'ErrorException' with message 'array_merge(): Argument #2 is not an array' in C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\View\Factory.php:150
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'array_merge(): ...', 'C:\wamp\www\aff...', 150, Array)
#1 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\View\Factory.php(150): array_merge(Array, Object(Zofe\Rapyd\DataGrid\DataGrid))
#2 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php(592): Illuminate\View\Factory->make('welcome', Object(Zofe\Rapyd\DataGrid\DataGrid), Array)
#3 C:\wamp\www\affichePCL\app\Http\Controllers\WelcomeController.php(67): view('welcome', Object(Zofe\Rapyd\DataGrid\DataGrid))
#4 [internal function]: affichePCL\Http\Controllers\WelcomeController->index()
#5 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Routing\Controller.php(246): call_user_func_array(Array, Array)
#6 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(162): Illuminate\Routing\Controller->callAction('index', Array)
#7 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(107): Illuminate\Routing\ControllerDispatcher->call(Object(affichePCL\Http\Controllers\WelcomeController), Object(Illuminate\Routing\Route), 'index')
#8 [internal function]: Illuminate\Routing\ControllerDispatcher->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#9 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(141): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#10 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#11 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(101): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#12 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(108): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#13 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(67): Illuminate\Routing\ControllerDispatcher->callWithinStack(Object(affichePCL\Http\Controllers\WelcomeController), Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'index')
#14 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Routing\Route.php(204): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'affichePCL\Http...', 'index')
#15 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Routing\Route.php(134): Illuminate\Routing\Route->runWithCustomDispatcher(Object(Illuminate\Http\Request))
#16 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Routing\Router.php(701): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#17 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#18 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(141): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#19 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#20 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(101): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#21 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Routing\Router.php(703): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#22 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Routing\Router.php(670): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#23 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Routing\Router.php(628): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#24 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(214): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#25 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#26 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(141): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#27 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php(43): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#28 C:\wamp\www\affichePCL\app\Http\Middleware\VerifyCsrfToken.php(17): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#29 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(125): affichePCL\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#30 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php(55): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#31 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(125): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#32 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(61): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#33 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(125): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#34 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php(36): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#35 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(125): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#36 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php(40): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#37 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(125): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#38 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php(42): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#39 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(125): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#40 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#41 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(101): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#42 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(115): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#43 C:\wamp\www\affichePCL\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(84): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#44 C:\wamp\www\affichePCL\public\index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#45 C:\wamp\www\affichePCL\server.php(21): require_once('C:\wamp\www\aff...')
#46 {main}
Could you help me please ?
Alain
It's because you're passing your data in the wrong way to the view. Instead of
return view('welcome',$grid);
You should be doing:
return view('welcome')->with('grid', $grid);
or
return view('welcome', ['grid' => $grid]);