1

I have a short PHP snippets on top of my blade file

<?php


use App\ImageWork, App\User, App\Skill, App\Contact, App\ActivityLog;

$images   = ImageWork::orderBy('created_at', 'desc')->get();
$users    = User::orderBy('created_at', 'desc')->get();
$logs     = ActivityLog::orderBy('created_at', 'desc')->get();
$skills   = Skill::orderBy('created_at', 'desc')->get();
$contacts = Contact::orderBy('created_at', 'desc')->get();

?>

I got this :

syntax error, unexpected 'use' (T_USE)

when I don't add that line, I got this

Class 'ImageWork' not found

What should I do now either way is wrong ?

Any hints / suggestions ?

7
  • Possible duplicate of PHP Parse/Syntax Errors; and How to solve them? Commented Mar 2, 2017 at 18:36
  • @aynber that Q&A doesn't have an entry for T_USE. Commented Mar 2, 2017 at 18:38
  • 3
    Is it even possible to use the use keyword in Blade templates? Try removing that line and changing ImageWork:: to App\Imagework:: etc. Also, this is something you should not be doing in your templates. Commented Mar 2, 2017 at 18:40
  • 1
    Just out of curiosity, why is this at the top of your blade file rather than being in a controller and then passed through? I can't honestly tell you the answer because the actual code itself looks fine but maybe considering moving it to your controller - if it doesn't work then, we can look at other reasons :) Commented Mar 2, 2017 at 18:41
  • 1
    A quick googling says that you can't, see e.g. stackoverflow.com/questions/18227439/… Commented Mar 2, 2017 at 18:41

1 Answer 1

2

Include the DB facade

use Illuminate\Support\Facades\DB;

And try to use that:

$images   = DB::table('ImageWork')->orderBy('created_at', 'desc')->get();
Sign up to request clarification or add additional context in comments.

2 Comments

Why should he use DB::table when he has models
If it work and the other models don´t get the same error he can isolate the problem to the ImageWork model and find what cause the error in the model.

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.