Property [image_thumb_url] does not exist on this collection instance - php

hello i just get an error in my blade it call
ErrorException (E_ERROR) Property [image_thumb_url] does not exist on
this collection instance. (View:
C:\xampp\htdocs\Madinatul-Quran\resources\views\backend\iklan\index.blade.php)
Previous exceptions Property [image_thumb_url] does not exist on this
collection instance. (0)
it start when i add modal in my index.blade does the controller caused that error?
here is my index.blade.php
<div id="modal_form_vertical" class="modal fade" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<form action="{{ route('iklan.store') }}" method="POST" enctype="multipart/form-data">
#csrf
<div class="modal-body">
<div class="form-group">
<div class="form-group col-sm-12 {{ $errors->has('image') ? 'has-error' : '' }}">
<div><label>Cover Iklan</label></div>
<div class="fileinput fileinput-new" data-provides="fileinput">
<div class="fileinput-new thumbnail" style="width: 200px; height: 100px;">
<img src="{{ ($ads->image_thumb_url) ? $ads->image_thumb_url : 'http://placehold.it/200x150&text=Landscape' }}" alt="...">
</div>
<div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 100px;"></div>
<div>
<span class="btn btn-default btn-file"><span class="fileinput-new">Pilih Gambar</span><span class="fileinput-exists">Ganti</span><input type="file" name='image'></span>
Hapus
</div>
</div>
#if($errors->has('image'))
<span class="help-block">{{ $errors->first('image') }}</span>
#endif
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-link" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
</div>
and this is my controller
public function index()
{
$ads = Ads::latest()->get();
return view("backend.iklan.index", compact('ads'));
}
public function store(Request $request)
{
$this->validate($request, [
'image' => 'mimes:jpeg,png,jpg,svg,bmp'
]);
$ads = new Ads;
$ads->author_id = Auth::user()->id;
if ($request->hasFile('image'))
{
$file = $request->file('image');
$image = $file->getClientOriginalName();
$destination = public_path() . '/imgiklan/';
$successUploaded = $request->file('image')->move($destination, $file->getClientOriginalName());
if($successUploaded)
{
$extension = $file->getClientOriginalExtension();
$thumbnail = str_replace(".{$extension}", "_thumb.{$extension}", $image);
Image::make($destination . '/' . $image)
->resize(250, 170)
->save($destination . '/' . $thumbnail);
}
$ads->image = $image;
} else {
$ads->image = 'logo.jpg';
}
$ads->save();
return redirect()->route('iklan.index')->with('message', 'Iklan berhasil dibuat');
}

Ads is plural, you're getting multiple ads sorted descending by created_at (because you're using latest()). In your view you're accessing an attribute of a single ad. You should therefore use this in your controller index route:
$ads = Ads::latest()->first();
Then $ads will be filled with the latest result in your database instead of a collection of ads.

Related

Missing required parameters for [Route]

I have this issue:
Illuminate\Routing\Exceptions\UrlGenerationException
Missing required parameter for [Route: admin.percent.edit] [URI: {locale}/admin/percent/edit/{id}] [Missing parameter: id]. (View: C:\Users\kawed\OneDrive\Desktop\flooss\resources\views\admin\includes\top.blade.php)
index page code:
#extends('admin.layouts.app')
#section('headSection')
<!-- form Uploads -->
<link href="{{ asset('back/assets/plugins/datatable/dataTables.bootstrap4.min.css') }}" rel="stylesheet" type="text/css" />
#endsection
#section('content')
<div class="page-header mt-0 shadow p-3">
<ol class="breadcrumb mb-sm-0">
<li class="breadcrumb-item">
{{ __('val.home') }}
</li>
<li class="breadcrumb-item active" aria-current="page">
{{ __('val.dashboard_percent') }}
</li>
</ol>
<a href="/{{ app()->getLocale() }}/admin/percent/create">
<button type="button" class="btn btn-success btn-pill mt-1 mb-1">{{ __('val.create_percent') }}</button>
</a>
</div>
<div class="row">
<div class="col-md-12">
<div class="card shadow">
<div class="card-header">
<h2 class="mb-0">Data Table</h2>
</div>
<div class="card-body">
<div class="table-responsive">
<table id="example" class="table table-striped table-bordered w-100 text-nowrap">
<thead>
<tr>
<th class="wd-15p">id</th>
<th class="wd-15p">{{ __('session.percent') }}</th>
<th class="wd-20p">{{ __('session.edit') }}</th>
<th class="wd-15p">{{ __('session.delete') }}</th>
</tr>
</thead>
<tbody>
#foreach($percents as $item)
<tr>
<td>
{{ $item->id }}
</td>
<td>
{{ $item->pname }}
</td>
<td>
{{ __('session.edit') }}
</td>
<td>
{{ __('session.delete') }}
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
#endsection
#section('footerSection')
<!-- file uploads js -->
<script src="{{ asset('back/assets/plugins/datatable/jquery.dataTables.min.js') }}"></script>
<script src="{{ asset('back/assets/plugins/datatable/dataTables.bootstrap4.min.js') }}"></script>
<script>
$(function(e) {
$('#example').DataTable();
var table = $('#example1').DataTable();
$('button').click(function() {
var data = table.$('input, select').serialize();
alert(
"The following data would have been submitted to the server: \n\n" +
data.substr(0, 120) + '...'
);
return false;
});
$('#example2').DataTable({
"scrollY": "200px",
"scrollCollapse": true,
"paging": false
});
});
</script>
#endsection
Edited page code:
#extends('admin.layouts.app')
#section('headSection')
<!-- form Uploads -->
<link href="{{ asset('back/assets/plugins/fileuploads/css/dropify.css') }}" rel="stylesheet" type="text/css" />
#endsection
#section('content')
<div class="page-header mt-0 shadow p-3">
<ol class="breadcrumb mb-sm-0">
<li class="breadcrumb-item">
{{ __('val.home') }}
</li>
<li class="breadcrumb-item active" aria-current="page">
{{ __('val.dashboard_percent') }}
</li>
</ol>
</div>
<div class="row">
<div class="col-md-12">
<form action="{{ route('admin.percent.edit', ['id' => $category->id, 'locale' => app()->getLocale()]) }}" method ="post" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="card shadow">
<div class="card-header">
<h2 class="mb-0">{{ __('val.edit_percent') }}</h2>
#include('admin.includes.messages')
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" name="categoryarabicname" value="{{ $category->categoryarabicname }}">
</div>
<div class="form-group">
<input type="text" class="form-control" name="categoryengname" value="{{ $category->categoryengname }}">
</div>
<div class="form-group">
<textarea class="form-control"name="categoryarabicdesc" id="exampleFormControlTextarea1" rows="3">{{ $category->categoryarabicdesc }}</textarea>
</div>
<div class="form-group">
<textarea class="form-control"name="categoryengdesc" id="exampleFormControlTextarea1" rows="3">{{ $category->categoryengdesc }}</textarea>
</div>
</div>
<div class="col-md-6">
<div class="card shadow">
<div class="card-header">
<h2 class="mb-0">Upload Image</h2>
</div>
<div class="card-body">
<input type="file" name="catimage" class="dropify" data-height="300" />
</div>
<input type="hidden" name="image2" class="form-control" id="exampleInputEmail1">
</div>
<div class="card shadow overflow-hidden">
<img alt="Image placeholder" width=250px height=250px class="big" src="/uploads/{{ $category->categoryimage }}">
</div>
</div>
<div class="col-lg-9"></div>
<div class="col-lg-3">
<button type="submit" class="btn btn-success btn-square mt-1 mb-1">Update</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
#endsection
#section('footerSection')
<!-- file uploads js -->
<script src="{{ asset('back/assets/plugins/fileuploads/js/dropify.min.js') }}"></script>
<script>
$('.dropify').dropify({
messages: {
'default': 'Drag and drop a file here or click',
'replace': 'Drag and drop or click to replace',
'remove': 'Remove',
'error': 'Ooops, something wrong appended.'
},
error: {
'fileSize': 'The file size is too big (2M max).'
}
});
</script>
#endsection
Controller code:
namespace App\Http\Controllers;
use App\Http\Requests\PercentEditRequest;
use App\Http\Requests\PercentRequest;
use App\Models\Percent;
use Illuminate\Http\Request;
class PercentController extends Controller
{
public function index()
{
$percents = Percent::orderBy('created_at', 'desc')->get();
return view('admin.percent.index', compact('percents'));
}
public function create()
{
return view('admin.percent.create');
}
public function store(PercentRequest $request)
{
$validated = $request->validated();
$category = new Percent();
$category->pname = strip_tags($request->pname);
$category->save();
return redirect()->route('admin.percent', ['locale' => app()->getLocale()])
->with('success', trans('session.success'));
}
public function edit(Request $request, $id) {
$id = $request->id;
$locale = $request->locale;
$category = Percent::find($id);
return view('admin/percent/edit', compact('category'));
}
public function update(PercentEditRequest $request, $id) {
$validated = $request->validated();
$category = Percent::find($id);
$category->categoryengname = strip_tags($request->categoryengname);
$category->categoryarabicname = strip_tags($request->categoryarabicname);
$category->categoryengdesc = strip_tags($request->categoryengdesc);
$category->categoryarabicdesc = strip_tags($request->categoryarabicdesc);
if (!empty($request->hasFile('catimage'))) {
$imagePath = $request->file('catimage');
$imageName = time() . '.' . $imagePath->getClientOriginalExtension();
$imagePath->move('uploads', $imageName);
$category->categoryimage= $imageName;
}
$category->save();
return redirect('/admin/percent')->with('success', 'percent Updated Successfuly');
}
public function destroy($id)
{
$category = Percent::find($id);
$category->delete();
return redirect('/admin/percent')->with('success','percent Deleted Successfuly');
}
}
you have 2 parameters in url as define (locale & id)
but in your function have only one id so add locale parameter
public function edit(Request $request, $locale, $id) {
or remove parameter from url and use it from request

Php search filter. Array returns NULL

This is Search Controller
if ($request->has('query')) {
$search = $request->get('query');
$search = addslashes(str_replace('"', '', json_encode($search)));
$solution = Service::all();
$solutions = array();
foreach ($solution as $id => $val) {
if (strpos(mb_strtolower($val['title']), mb_strtolower($search))) {
$solutions[] = $solution[$id];
}
}
}
When I run the dd command, 10 pieces of data appear.
For example when I search for 'customer' the array returns null even though this data is exist.
This is search.blade.php
<div class="header-search-form default-search">
<form action="{{ route('search') }}" method="GET" class="search-form-top">
<input class="search-field" type="text" name="query" id="query" value="{{ request()->input('query') }}" placeholder="{{ trans('general.search') }}">
<button class="search-submit">
<i class="search-btn-icon fa fa-search"></i>
</button>
</form>
</div>
This is search-result.blade.php
<div class="row row--35">
#foreach ($solutions as $solution)
<div class="col-lg-4 col-md-6 mt-10" >
<a href="{{route('service_detail',$solution->slug)}}" class="box-large-image__wrap wow move-up">
<div class="box-large-image__box">
<div class="box-large-image__midea">
<div class="images-midea">
<img src="{{ coverImg('service',$solution->id) }}" class="img-fluid" alt="">
<div class="button-wrapper">
<div class="btn tm-button">
<span class="button-text">Detayları Gör</span>
</div>
</div>
<div class="heading-wrap">
<h5 class="heading">{{ $solution->title }}</h5>
</div>
</div>
</div>
<div class="box-large-image__content mt-30 text-center"></div>
</div>
</a>
</div>
#endforeach
</div>

Laravel 7: User Profile causing bug when uploading img and bio description

In a laravel 7 app I'm working on a feature where a user can upload their image profile and bio description. A problem that I'm facing is that there are certain cases when a user sets their profile image, the bio description would be gone. For example: If a user set their profile img and puts a description, but if the user sets another img then the description would be gone. Not quite sure what's the bugs that's causing it. (I'm using bootstrap modal for the user to edit their profile.)
controller.php
public function modalEditPost(Request $request)
{
$user = Auth::user();
$avatarName = "";
$userBio = "";
$request->validate([
'bio' => 'nullable|string|max:255',
'image' => 'mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
if ($request->has('bio')) {
$userBio = $request->bio;
$user->bio = $userBio;
}
if ($request->hasFile('image')) {
if ($request->file('image')->isValid()) {
$extension = $request->image->extension();
$avatarName = $user->id.'_avatar'.time().'.'.$extension;
$request->image->move(public_path('/uploads/avatars'), $avatarName);
$user->avatar = $avatarName;
}
}
$user->save();
return back()
->with('success','You have successfully edited your bio.')
->with('bio', $userBio)
->with('image', $avatarName);
}
index.blade.php
#include('partials.popup')
<div class="col-md-4">
<div class="card card-user">
<div class="card-body">
<p class="card-text">
<div class="author">
<div class="block block-one"></div>
<div class="block block-two"></div>
<div class="block block-three"></div>
<div class="block block-four"></div>
<img class = "avatar" src="/uploads/avatars/{{ Auth::user()->avatar}}" alt="">
<h4 class="title">{{ auth()->user()->first_name }} {{ auth()->user()->last_name }}</h5>
</div>
<div class="card-description">
{{ Auth::user()->bio }}
</div>
<br>
<div class="text-center">
<button class="btn btn-success"
style="cursor: pointer"
data-toggle="modal"
data-target="#popupModal">{{ __('Edit Profile') }}
</button>
</div>
</div>
</div>
popup.blade.php
<div class="modal-body">
<!-- (Image upload) Start -->
#if ($message = Session::get('success'))
<div class="alert alert-success alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
</div>
#endif
#if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<!-- (Image upload) Start -->
<form action="{{ route('modal.upload.post') }}" method="POST" enctype="multipart/form-data">
#csrf
<div class="row">
<div class="col-md-6">
<input type="file" name="image" class="form-control-file">
</div>
</div>
<br>
<div class="row">
<div class="col">
<p>Change Bio</p>
</div>
</div>
<div class="row">
<div class="col">
<input type="text" style="color:black" name="bio" class="form-control">
</div>
</div>
<br>
<div class="col-md-6">
<button type="submit" class="btn btn-success">Update</button>
</div>
</form>
<!-- (Image upload) End -->
</div>

Laravel : Update form keeping current image without input a new image isn't working

I have a form with image field, inserting all the field with image works fine
but when editing the form->to update a new image I used unlink function to remove the previous image and update with new one. The problem is if I don't upload a new image and submit the form it isn't working.
But I want to keep the current image remain if new image is not uploaded. I have tried many ways even not using unlink function but couldn't reach any solution. please help me, I really need this solution. Thanks in advance
here is my update function in controller
public function Update(Request $request, $id){
$PreviousPic = $request->Prev_pic;
$data = array();
$data['student_name'] = $request->student_name;
$data['matric_no'] = $request->matric_no;
$data['programme_name'] = $request->programme_name;
$data['faculty_name'] = $request->faculty_name;
$data['admission_year'] = $request->admission_year;
$data['contact_no'] = $request->contact_no;
$image = $request->file('pro_pic');
if ($image){
unlink($PreviousPic);
$image_name = date('dmy_H_s_i');
$ext = strtolower($image->getClientOriginalExtension());
$imageFullName = $image_name.'.'.$ext;
$uploadPath = 'media/';
$imageURL = $uploadPath.$imageFullName;
$success = $image->move($uploadPath,$imageFullName);
$data['pro_pic'] = $imageURL;
$Stdata = DB::table('students')->where('id', $id)->update($data);
return redirect()->route('student.index')
->with('success','Updated! The Student Data Updated Successfully');
}
}
here is my edit form image field
<div class="form-group">
<label class="col-md-4 control-label" >Image</label>
<div class="col-md-5 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-picture"></i></span>
<div class="upload-btn-wrapper">
<button class="btn">Upload a New Image</button>
<input type="file" name="pro_pic" />
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Current Image </label>
<div class="col-md-5 inputGroupContainer">
<img src="{{ URL::to($StudentData->pro_pic)}}" height="150px" width="190px">
<input type="hidden" name="Prev_pic" value="{{$StudentData->pro_pic}}">
</div>
</div>
Using this I can upload new image removing the old picture. But If I keep the Upload a New Image field empty and submit the form, the form isn't submitted.
So, I want if I upload new image it works as now and if I don't upload a new image, the current image will remain & submit the form.
# I am using Laravel 7
I have found the answer as expected
public function Update(Request $request, $id){
$PreviousPic = $request->Prev_pic;
$data = array();
$data['student_name'] = $request->student_name;
$data['matric_no'] = $request->matric_no;
$data['programme_name'] = $request->programme_name;
$data['faculty_name'] = $request->faculty_name;
$data['admission_year'] = $request->admission_year;
$data['contact_no'] = $request->contact_no;
$image = $request->file('pro_pic');
if ($image != null){
unlink($PreviousPic);
$image_name = date('dmy_H_s_i');
$ext = strtolower($image->getClientOriginalExtension());
$imageFullName = $image_name.'.'.$ext;
$uploadPath = 'media/';
$imageURL = $uploadPath.$imageFullName;
$success = $image->move($uploadPath,$imageFullName);
$data['pro_pic'] = $imageURL;
$Stdata = DB::table('students')->where('id', $id)->update($data);
return redirect()->route('student.index')
->with('success','Updated! The Student Data Updated Successfully');
}else{
$Stdata = DB::table('students')->where('id', $id)->update($data);
return redirect()->route('student.index')
->with('success','Updated! The Student Data Updated Successfully');
}
}
Just use if else statement to find the solution and it's working great.
You need to pass the exact path of the old image from database.
You can try it with concatenation,
By making two separate columns for image_name and image_path
This is my edit image code
<div id="image" class="row" style="display: none;">
<div class="col-md-12">
<label for="text">Project Image</label>
<div class="form-group">
<input type="file" class="form-control" name="project_image"
value="{{ old('project_image',$currentProject->project_image) }}">
#if ($errors->has('project_image'))
<div class="text-danger">{{ $errors->first('project_image') }}</div>
#endif
</div>
</div>
</div>
This is the div to view the previous and new image
<div class="box box-primary">
<div class="box-body">
<div class="box-header text-center">
<h3 class="box-title">Project Cover Image</h3>
</div>
<div class="row">
<div class="col-md-12 text-center">
<img class="img-responsive" src="{{ URL::asset($currentProject->project_cover_image_path.'/'.$currentProject->project_cover_image_name)}}" alt="Photo">
<br>
<a class="btn btn-primary" data-toggle="modal" data-target="#modal-project-cover">
Change Cover Image
</a>
</div>
</div>
</div>
</div>
This is the modal that actually edits the image
{{-- Modal dialogue to edit Project Cover Image --}}
<div class="modal fade" id="modal-project-cover">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header text-center">
<form method="POST" action="{{url('updateprojectcover', $currentProject->project_id)}}" enctype="multipart/form-data">
<input type="hidden" value="{{ csrf_token() }}" name="_token">
#if (session('error'))
<div class="alert alert-danger">{{ session('error') }}</div>
#endif
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×
</span>
</button>
<div class="row">
<div class="col-md-12">
<h4 for="text">Project Cover Image</h4>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group text-center">
<input type="file" class="form-control" name="project_cover_image">
#if ($errors->has('project_cover_image'))
<div class="text-danger">{{ $errors->first('project_cover_image') }}
</div>
#endif
</div>
</div>
</div>
<div class="modal-footer text-center">
<button type="submit" class="btn btn-primary text-center">Yes</button>
</div>
</form>
</div>
</div>
</div>
</div>
This is my controller to edit image
try
{
$cover_name = $request->file('project_cover_image');
if (isset($cover_name))
{
$project_cover_image_name = $cover_name->getClientOriginalName();
$project_cover_image_name = str_replace(" ", "_", time() . $project_cover_image_name);
$cover_name->move(ImageUrlController::$project_cover_image_path, $project_cover_image_name);
}
Project::where('project_id', $project_id)
->update([
'project_cover_image_path' => ImageUrlController::$project_cover_image_path,
'project_cover_image_name' => $project_cover_image_name,
'updated_at' => Carbon::now('PKT'),
]);
return redirect()->back()->withInput();
}
catch (\Exception $exception)
{
return back()->withError($exception->getMessage())->withInput();
}

Laravel 5.8, CRUD when editing image didn't show up (blade)?

I try to create edit blade to get old value from database. the title successfully appears, but the image and body (textarea) didn't appears,
here is some code of my edit.blade.php
<form action="{{ route('blog.update', $post->id) }}" method="PUT" enctype="multipart/form-data" id='post-form'>
#csrf
<div class="form-group">
<label>Isi</label>
<textarea rows="5" cols="5" class="form-control" name="body" value="{{$post->body}}"></textarea>
</div>
<div class="panel panel-flat">
<div class="image-news">
<span>Cover Berita</span>
<ul class="icons-list">
<li></li>
</ul>
</div>
<div class="category-content">
<div class="form-group ">
<div class="fileinput fileinput-new" data-provides="fileinput">
<div class="fileinput-new thumbnail" style="width: 200px; height: 150px;">
<img src="{{ $post->image_thumb_url ? $post->image_thumb_url : 'http://placehold.it/200x150&text=no+image' }}" alt="...">
</div>
<div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"></div>
<div>
<span class="btn btn-default btn-file"><span class="fileinput-new">Pilih Gambar</span><span class="fileinput-exists">Ganti</span><input type="file" name='image'></span>
Hapus
</div>
</div>
</div>
</div>
</div>
And here is my contoller connect to edit.blade.php
public function store(Request $request)
{
$post = new Post;
$post->title = $request->get('title');
// $post->excerpt = $request->get('excerpt');
$post->body = $request->get('body');
$post->published_at = $request->get('published_at');
$post->category_id = $request->get('category_id');
$post->author_id = Auth::user()->id;
if ($request->hasFile('image'))
{
$file = $request->file('image');
$image = $file->getClientOriginalName();
$destination = public_path() . '/imgberita/';
$successUploaded = $request->file('image')->move($destination, $file->getClientOriginalName());
if($successUploaded)
{
$extension = $file->getClientOriginalExtension();
$thumbnail = str_replace(".{$extension}", "_thumb.{$extension}", $image);
Image::make($destination . '/' . $image)
->resize(250, 170)
->save($destination . '/' . $thumbnail);
}
$post->image = $image;
}else{
$post->image = 'logo.jpg';
}
$post->save();
return redirect()->route('blog.index')->with('message', 'Berita berhasil dibuat');
}
public function edit($id)
{
$post = Post::findOrFail($id);
return view("backend.blog.edit", compact('post'));
}
Can anyone help me, how to show image the right way in edit.blade.php
For this line of your code please change as follow:
From:
<img src="{{ $post->image_thumb_url ? $post->image_thumb_url : 'http://placehold.it/200x150&text=no+image' }}" alt="...">
To:
<img src="{{ $post->imageThumb ?? 'http://placehold.it/200x150&text=no+image' }}" alt="...">
Then add the following function to your Post model:
public function imageThumb(){
if($this->image_thumb_url){
if(File::exists(public_path() . '/imgberita/'.$this->image_thumb_url)){
return public_path() . '/imgberita/'.$this->image_thumb_url;
}
}
return null;
}
Then use the function in your view like this if that image exist it will return the location if not exist it will return the null.
$post->imageThumb
If you get issue with this function just update the public_path() . '/imgberita/' inside the function, hope you get idea.
For textare you can use the old() function in your view:
<textarea rows="5" cols="5" class="form-control" name="body" value="{{$post->body}}"></textarea>
For example like this:
<textarea rows="5" cols="5" class="form-control" name="body" value="{{old('body') ?? ''}}"></textarea>
But remember we use the old('body') function when we use the validate() and we pass the data from controller by using ->withInput() like this:
return redirect()
->back()
->withInput()
->withErrors($validator);
Also you can directly pass data in your edit.blade.php by using with($request) function.
If your body is null you will get error then use the {{$post->body ?? ''}}.
Change this
<img src="{{ $post->image_thumb_url ? $post->image_thumb_url : 'http://placehold.it/200x150&text=no+image' }}" alt="...">
to
<img src="{{ $post->image_thumb_url ? asset('/imgberita/'.$post->image_thumb_url) : 'http://placehold.it/200x150&text=no+image' }}" alt="...">
OR
<img src="{{ $post->image_thumb_url ? asset('public/imgberita/'.$post->image_thumb_url) : 'http://placehold.it/200x150&text=no+image' }}" alt="...">

Categories