problem with an eloquent query

1

my problem is the following I do not manage to capture the id to perform the update function I get the following error: undefined index: id this is the code:

public function getUpdate() {
    $id = $_GET['id'];
    $blogPosts = BlogPost::find($id);
    $titleValue = $blogPosts['title'];
    $contentValue = $blogPosts['content'];

    return $this->render('admin/update-post.twig', [
        'titleValue' => $titleValue,
        'contentValue' => $contentValue,
        'id' => $id
    ]);     
}
    
asked by Carlos Hernández 11.07.2018 в 02:54
source

2 answers

0

Friend the solution for that problem is, when you are sending the id through the get method, you should do something like that.

  

link {id}

Which then in the get function you will receive as an argument.

public function getUpdate($id) {
    $blogPosts = BlogPost::find($id);
    $titleValue = $blogPosts['title'];
    $contentValue = $blogPosts['content'];

    return $this->render('admin/update-post.twig', [
        'titleValue' => $titleValue,
        'contentValue' => $contentValue,
        'id' => $id
    ]);     
}
    
answered by 11.07.2018 / 06:01
source
1

In the routes.php file you have to put the variable id so that it can be collected in your controller, for example

Route::get('/update/{id}', 'TuControlador@getUpdate');

And in the controller in your function all you have to do is start that variable:

public function getUpdate($id) {
    $blogPosts = BlogPost::find($id);
    //resto de tu codigo
}
    
answered by 11.07.2018 в 10:45