I have the following edit method in my laravel controller:
public function editArtilce(Request $request) {
/* Get the last part of the URI */
$explodedUrl = explode('/', $request->url());
$urlSlug = array_pop($explodedUrl);
$article = DB::table('admin')->where('slug', 'LIKE', '%' . $urlSlug . '%')->get();
return $article;
}
Now since i am doing:
return $article;
I get the following output in the browser:
[{"id":10,"title":"This is a title","description":"This is a description","keywords":"Keyword1 , Keyword2 , Keyword3 , Keyword4 , Keyword5 , Keyword6","blog_content":"<p>I am a lovely burger<\/p>","tag":"gulp","filePath":"2017-02-23-21-54-30-blog-post-image.jpg","slug":"this-is-a-title","created_at":"2017-02-23 21:54:30","updated_at":"2017-02-23 21:54:30"},{"id":11,"title":"This is a title","description":"This is a description","keywords":"Keyword1 , Keyword2 , Keyword3 , Keyword4 , Keyword5 , Keyword6","blog_content":"<p>I am a lovely burger<\/p>","tag":"gulp","filePath":"2017-02-23-21-56-29-blog-post-image.jpg","slug":"this-is-a-title","created_at":"2017-02-23 21:56:29","updated_at":"2017-02-23 21:56:29"}]
But when i try to access the properties of this array like so:
return $article->title
I get the following error:
Why am i unable to access the properties of an array in laravel ? What am i doing wrong ?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire