mukhtiar's avatar

test

i am mukhtiar can any response me

0 likes
11 replies
mukhtiar's avatar

thanks for giving me response i want to check that is there give me anyone response or not

mukhtiar's avatar

i am new in laravel i m feeling confusion it is my route Route::get('/article/{id}','ArticleController@single'); and it is my controller

public function single($id) {
$id=Article::findOrFail($id); // $articles = DB::table('articles')->where('id', 1)->first(); $articles = DB::table('articles') ->select('id','name', 'roll_no') ->where('id', '=', 1) ->get();

return View('single',compact('articles'));

} i want to fetch only id releated data but it is not working

joedawson's avatar

Your route looks ok. Try this:

public function single($id)
{
    $article = Article::findOrFail($id);

    return view('single', compact('article'));
}

Previously, you were assigning you article to an $id variable which you're not passing through to the view.

mukhtiar's avatar

i have checked id is coming i have print id and it is 1or 2....but the problem is the same

mukhtiar's avatar

and $articles fetch all the data from the database

mukhtiar's avatar

it just give me id fetch from database nothing else

joedawson's avatar

In your view, nothing is displayed when you visit /articles/ followed by an existing ID in your database?

mukhtiar's avatar

[timestamps] => 1 [attributes:protected] => Array ( [id] => 2 [name] => new article [roll_no] => 2352 [created_at] => 2015-11-23 00:00:00 [updated_at] => 2015-11-23 00:00:00 )

[original:protected] => Array
    (
        [id] => 2
        [name] => new article
        [roll_no] => 2352
        [created_at] => 2015-11-23 00:00:00
        [updated_at] => 2015-11-23 00:00:00
    )

i have fetch the data from the database and it is shown in this format(print_r($articles)) but i want to show on page using foreach but nothis is display this is my view page

foreach ($articles as $value) { echo "
";
print_r($articles);

?>
<h1>User Name:</h1><?php echo $value['name'];?>
<h1>User Roll No:</h1><?php echo  $value['roll_no'];?>
<?php 

}

?>

mukhtiar's avatar

oh i have got the probleam...... i am using foreach but the data is not in arrayformat now it is working ...

... ... ... i am thankful for you by giving me response and giving me hint thanks bro....

Please or to participate in this conversation.