So this a really newbie question but I need a better understanding of how does work Laravel and PHP.
I'd like to access an array from the blade with something like {{$article->title}} or {{$article['title']}}
The only way I found it was to create an stdClass() and attribute each of the value of the array to the new object.
$article = new \stdClass();
$article->id = "";
$article->title = "";
$article->content = "";
$article->created_at = "";
$article->updated_at = "";
if($var != null){
$tmp = DB::select('select * from articles where id = ' . $var);
$article->id = $tmp[0]->id;
$article->title = $tmp[0]->title;
$article->content = $tmp[0]->content;
$article->created_at = $tmp[0]->created_at;
$article->updated_at = $tmp[0]->updated_at;
}
However this is pretty ugly and I'd like to know what is the proper way of doing it.
I tried to keep it simple with
$article = DB::select('select * from articles where id = ' . $var);
But I dont find a way to access $article in my blade template.
This is the var_dump of it :
array (size=1)
0 =>
object(stdClass)[170]
public 'id' => int 1
public 'title' => string 'Test' (length=4)
public 'content' => string '<p>Test</p>' (length=151)
public 'created_at' => string '2016-12-21 10:00:04' (length=19)
public 'updated_at' => string '2016-12-21 10:15:57' (length=19)