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 ?

code-8
  • 54,650
  • 106
  • 352
  • 604
  • Possible duplicate of [PHP Parse/Syntax Errors; and How to solve them?](http://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – aynber Mar 02 '17 at 18:36
  • @aynber that Q&A doesn't have an entry for `T_USE`. – Jonathan Kuhn Mar 02 '17 at 18:38
  • @JonathanKuhn Ah, okay, I'll withdraw it. – aynber Mar 02 '17 at 18:39
  • 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. – Joel Hinz Mar 02 '17 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 :) – Ryan Lund Mar 02 '17 at 18:41
  • 1
    A quick googling says that you can't, see e.g. http://stackoverflow.com/questions/18227439/use-php-namespace-inside-function – Joel Hinz Mar 02 '17 at 18:41
  • Why not use `Controller` to do the query job? – Ali Rasheed Mar 03 '17 at 02:04

1 Answers1

2

Include the DB facade

use Illuminate\Support\Facades\DB;

And try to use that:

$images   = DB::table('ImageWork')->orderBy('created_at', 'desc')->get();
brunohdaniel
  • 612
  • 5
  • 18