PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Fri Oct 20, 2017 12:20 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Fri Jul 28, 2017 4:31 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 331
I have the folllowing route in my route.php file:

Syntax: [ Download ] [ Hide ]
Route::get('/edit/{id}' , [
        'uses' => 'adminController@editArticle',
        'as' => 'editArticle'
]);
 


The editArticle function looks like the folllowing:

Syntax: [ Download ] [ Hide ]
public function editArticle(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 . '%')->first();
                return $article;
                // $tagsArray = $this->getTags();
                return view('pages.editArticle')->with('article', $article)->with('tags' , $tagsArray);
}
 


now when i type the following into my URL in the browser:

Syntax: [ Download ] [ Hide ]
http://localhost:8080/laravel-blog-prod ... -keyframes
 


I get the following error:
http://imgur.com/a/tynu6

Syntax: [ Download ] [ Hide ]
The Response content must be a string or object implementing __toString(), "object" given.
 


Just to clarify , i have a admin table and in it i have a slug column in which i do have a value of
Syntax: [ Download ] [ Hide ]
animated-button-border-using-css-background-and-keyframes
 


as you must have seen in the url.

I am not sure what is causing this bug and how should i go about resolving this ?

can somebody help me out please.

Thank you.
Gautam.


Top
 Profile  
 
PostPosted: Fri Jul 28, 2017 4:58 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6573
Location: WA, USA
Syntax: [ Download ] [ Hide ]
return $article;

That's the bug. Why is that there?


Top
 Profile  
 
PostPosted: Fri Jul 28, 2017 5:01 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 331
@requinix , because i wanna see whats retrived in the $article variable , also if i remove that variable the next line throws the same error.


Top
 Profile  
 
PostPosted: Fri Jul 28, 2017 5:55 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6573
Location: WA, USA
You can't just decide to change a return value from a function and expect Laravel to somehow make it work.

Look at the trace and you can tell that $article is a stdClass. That's because it came from a database query using PDO. Laravel doesn't know what to do with a stdClass.

Are you saying that removing that line and uncommenting the next one that defines $tagsArray causes
Syntax: [ Download ] [ Hide ]
return view('pages.editArticle')->with('article', $article)->with('tags' , $tagsArray);

that line to error? What message and what does the trace show?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group