Error url $feed->id

Asked

Viewed 66 times

1

Hello, I am working on a system with feed scheme. Clicking on "Edit" appears the following error:

SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "$feed->id" (SQL: select * from "feeds" Where "feeds"." id" = $feed->id limit 1)

I realized in the URL where it was to have something like:

http://localhost:8000/feed/2/update

he appears as:

http://localhost:8000/feed/$feed->id/update

How to resolve this? I hope you have made my doubt clear. I thank you in advance.

Codes:

home.blade.php (home)

@extends('layouts.app')

@section('content')
<div class="container">
   @forelse($feeds as $feed)
      <h1>{{$feed->title}}</h1>
      <p>{{$feed->description}}</p>
      <b>Publicado por: {{$feed->user->name}}</b>
      <a href="{{url('/feed/$feed->id/update')}}">Editar</a>
      <hr>
   @empty
      <p>Nenhum chamado cadastrado!</p>
   @endforelse
</div>
@endsection

web.php (routes)

<?php
Route::get('/', function () {
return view('auth/login');
});

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

Route::get('feed/{id}/update', 'HomeController@update');

Homecontroller.php (controller)

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\feed;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(feed $feed)
    {
        //$feeds = $feed->all();
        $feeds = $feed->where('user_id', auth()->user()->id)->get();

        return view('home', compact('feeds'));
    }

    public function update($idFeed)
    {
        $feed = feed::find($idFeed);

        return view('feed-update', compact('feed'));
    }
}

feed-update.blade.php (feed view)

@extends('layouts.app')

@section('content')
<div class="container">
    <h1>{{$feed->title}}</h1>
    <p>{{$feed->description}}</p>
    <b>Publicado por: {{$feed->user->name}}</b>    
</div>
@endsection
  • If possible post your code.

  • All right, that’s three files from the lockbox, one moment.

  • Just need the line you set the URL on. You probably generated a string badly formatted.

  • It’s all right with me, but I’m just a beginner so...

  • 1

    The problem is in {{url('/feed/$feed->id/update')}}. Utilize {{url('/feed/'.$feed->id.'/update')}} or {{url("/feed/{$feed->id}/update")}}

  • It worked, thank you very much.

  • To ROBERTO DE CAMPOS who is editing my question, removing the education arguments, respect first, and second, the next time you edit a question, add arguments that are important.

  • @João.Mistura This is an understanding of the community. https://pt.meta.stackoverflow.com/a/851/99718

  • Okay, I didn’t know vlw

Show 4 more comments

1 answer

1


I believe the problem lies in this passage <a href="{{url('/feed/$feed->id/update')}}">Editar</a> home.blade.php file where $feed->id is inside simple quotes. Try it this way:

<a href="{{url('/feed/' . $feed->id .'/update')}}">Editar</a>

Or else:

<a href="{{url(sprintf( '/feed/%s/update', $feed->id ))}}">Editar</a>
  • It’s worked, but thanks anyway :)

  • worked with {{url('/feed/{$feed->id}/update')}}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.