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.
– Valdeir Psr
All right, that’s three files from the lockbox, one moment.
– João.Mistura
Just need the line you set the URL on. You probably generated a string badly formatted.
– Woss
It’s all right with me, but I’m just a beginner so...
– João.Mistura
The problem is in
{{url('/feed/$feed->id/update')}}
. Utilize{{url('/feed/'.$feed->id.'/update')}}
or{{url("/feed/{$feed->id}/update")}}
– Elanio
It worked, thank you very much.
– João.Mistura
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
@João.Mistura This is an understanding of the community. https://pt.meta.stackoverflow.com/a/851/99718
– Valdeir Psr
Okay, I didn’t know vlw
– João.Mistura