Your $things array seems to be empty. Did you try to dd($things) in the view to check if the error comes from there?
By the way you don't have a property called doc_title in your array, but you try to access it in the view (just as a side note).
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi there,
I hope that you can help. I am using Laravel 5.3 and Laravel Spark 3.
I'm currently working on a site that will allow a user to email a link to a page that, clicked on, displays a list of their things to the email recipient. The list I am currently experimenting with only has one thing in it, but in a real world situation, there will be many more.
Before posting here, I have read about Many to Many Eloquent Models, watched the archived Laracast series on it and viewed some YouTube posts from DevMarketer.
The database has several tables, including, 'lists', 'things', 'links', and a pivot table, 'list_thing'. The 'links' table has a column for 'list_link_token' which is a hashed string of 5 characters which is added to the end of the link that is sent to the recipient. The link therefore might look like: our-site.com/sudfk.
In the LinkController there is code that looks like this:
<?php
namespace Laravel\Spark\Http\Controllers\Settings\SharedThings;
use Laravel\Spark\Spark;
use Laravel\Spark\Link;
use Laravel\Spark\List;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Laravel\Spark\Http\Controllers\Controller;
class LinkController extends Controller
{
/**
* Set the view to be publicly accessible
*
* @return void
*/
public function __construct()
{
}
/**
* Show the shared things view
*
* @return Response
*/
public function show($listLinkToken)
{
$listId = Link::where('list_link_token', $listLinkToken)->value('list_id');
$list = List::where('id', $listId)->first();
$things = $list->things->toArray();
Log::debug($things);
// die();
return view('spark::settings.sharedthings')->with('things', $things);
}
}
The array that Log returns looks like this:
array (
0 =>
array (
'id' => 32,
'user_id' => 85,
'thing_title' => 'Test Item',
'thing_type_id' => 6,
'primary_identifier' => 'qwert-153',
'main_img_url' => '/storage/things/91ebaa727fd585299a53c055a72005d7.png',
'created_at' => '2017-06-05 14:06:50',
'updated_at' => '2017-06-05 14:24:53',
'pivot' =>
array (
'list_id' => 29,
'thing_id' => 32,
),
),
)
So, the correct thing is being picked up for the given list, based on the known list_link_token.
The blade includes this:
@foreach($things as $thing)
<div class="thingimgview">
<div class="thingimg-cont">
<img src="{{ $thing->main_img_url }}" alt="{{ $thing->thing_title }}">
</div>
<p class="thingimg-title">
{{ $thing->thing_title }}
</p>
</div>
@endforeach
There must be something I am doing wrong because the view's not being returned. Instead, I get this error:
ErrorException in e462aafaa3ba1c26070d9daefb26f4cbbac135c3.php line 12:
Trying to get property of non-object (View: /var/www/vhosts/our-site.com/laravel/resources/views/vendor/spark/settings/shareddocs/list-shareddocs.blade.php) (View: /var/www/vhosts/our-site.com/laravel/resources/views/vendor/spark/settings/shareddocs/list-shareddocs.blade.php)
in e462aafaa3ba1c26070d9daefb26f4cbbac135c3.php line 12
at CompilerEngine->handleViewException(object(ErrorException), '1') in PhpEngine.php line 44
at PhpEngine->evaluatePath('/var/www/vhosts/our-site.com/laravel/storage/framework/views/597dc08d998a5e98c40dfdbbb0c602217fb38deb.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'things' => array(array('id' => '32', 'user_id' => '85', 'thing_title' => 'Test item', 'thing_type_id' => '6', 'primary_identifier' => 'qwert-153', 'main_img_url' => '/storage/documents/91ebaa727fd585299a53c055a72005d7.png', 'created_at' => '2017-06-05 14:06:50', 'updated_at' => '2017-06-05 14:24:53', 'pivot' => array('list_id' => '29', 'thing_id' => '32'))))) in CompilerEngine.php line 59
at CompilerEngine->get('/var/www/vhosts/our-site.com/laravel/resources/views/vendor/spark/settings/shareddocs.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'things' => array(array('id' => '32', 'user_id' => '85', 'thing_title' => 'Test item', 'thing_type_id' => '6', 'primary_identifier' => 'qwert-153', 'main_img_url' => '/storage/documents/91ebaa727fd585299a53c055a72005d7.png', 'created_at' => '2017-06-05 14:06:50', 'updated_at' => '2017-06-05 14:24:53', 'pivot' => array('list_id' => '29', 'thing_id' => '32'))))) in View.php line 149
at View->getContents() in View.php line 120
at View->renderContents() in View.php line 85
at View->render() in Response.php line 45
at Response->setContent(object(View)) in Response.php line 201
at Response->__construct(object(View)) in Router.php line 1028
at Router->prepareResponse(object(Request), object(View)) in Router.php line 653
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CreateFreshApiToken.php line 40
at CreateFreshApiToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 65
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Router.php line 655
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 629
at Router->dispatchToRoute(object(Request)) in Router.php line 607
at Router->dispatch(object(Request)) in Kernel.php line 268
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in HandleCors.php line 36
at HandleCors->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 150
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
at Kernel->handle(object(Request)) in index.php line 53
Please could you point me in the right direction, with some code examples?
Any help'd be most appreciated.
With kind regards,
Mark
Never mind I think I know what the problem is:
You're trying to do this
{{ $thing->thing_title }}
// it should be
{{ $thing['thing_title'] }}
Try it and get back to me. P.S. of course try it on all objects...
Please or to participate in this conversation.