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="...">
Related
After setting up my profile page my uploaded images initially produced an image on my local host. However lately it shows up as an icon instead https://i.stack.imgur.com/pp0Yt.png
I should note I am using php 7.3.19
profiles/index.blade.php
<div class="container">
<div class="row">
<div class="col-3 p-5">
<img src="{{ $user->profile->profileImage() }}" class="rounded-circle w-100">
</div>
<div class="col-9 pt-5">
<div class="d-flex justify-content-between align-items-baseline">
<div class="d-flex align-items-center pb-3">
<div class="h4">{{ $user->username }}</div>
<follow-button user-id="{{ $user->id }}" follows="{{ $follows }}"></follow-button>
</div>
#can('update', $user->profile)
Add New Post
#endcan
</div>
#can('update', $user->profile)
Edit Profile
#endcan
<div class="d-flex">
<div class="pr-5"><strong>{{ $postCount }}</strong> posts</div>
<div class="pr-5"><strong>{{ $followersCount }}</strong> followers</div>
<div class="pr-5"><strong>{{ $followingCount }}</strong> following</div>
</div>
<div class="pt-4 font-weight-bold">{{ $user->profile->title }}</div>
<div>{{ $user->profile->description }}</div>
<div>{{ $user->profile->url }}</div>
</div>
</div>
<div class="row pt-5">
#foreach($user->posts as $post)
<div class="col-4 pb-4">
<a href="/p/{{ $post->id }}">
<img src="/storage/{{ $post->image }}" class="w-100">
</a>
</div>
#endforeach
</div>
</div>
#endsection
Is there an issue in the way I am picking it up from the storage?
I used 'php artisan storage:link'
create.blade.php
<div class="container">
<form action="/p" enctype="multipart/form-data" method="post">
#csrf
<div class="row">
<div class="col-8 offset-2">
<div class="row">
<h1>Add New Image</h1>
</div>
<div class="form-group row">
<label for="caption" class="col-md-4 col-form-label">Post Caption</label>
<input id="caption"
type="text"
class="form-control{{ $errors->has('caption') ? ' is-invalid' : '' }}"
name="caption"
value="{{ old('caption') }}"
autocomplete="caption" autofocus>
#if ($errors->has('caption'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('caption') }}</strong>
</span>
#endif
</div>
<div class="row">
<label for="image" class="col-md-4 col-form-label">Post Image</label>
<input type="file" class="form-control-file" id="image" name="image">
#if ($errors->has('image'))
<strong>{{ $errors->first('image') }}</strong>
#endif
</div>
<div class="row pt-4">
<button class="btn btn-primary">Add New Post</button>
</div>
</div>
</div>
</form>
</div>
#endsection
PostsController.php
<?php
namespace App\Http\Controllers;
use App\Post;
use Illuminate\Http\Request;
use Intervention\Image\Facades\Image;
class PostsController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
$users = auth()->user()->following()->pluck('profiles.user_id');
$posts = Post::whereIn('user_id', $users)->with('user')->latest()->paginate(5);
return view('posts.index', compact('posts'));
}
public function create()
{
return view('posts.create');
}
public function store()
{
$data = request()->validate([
'caption' => 'required',
'image' => ['required', 'image'],
]);
$imagePath = request('image')->store('uploads', 'public');
$image = Image::make(public_path("storage/{$imagePath}"))->fit(1200, 1200);
$image->save();
auth()->user()->posts()->create([
'caption' => $data['caption'],
'image' => $imagePath,
]);
return redirect('/profile/' . auth()->user()->id);
}
public function show(\App\Post $post)
{
return view('posts.show', compact('post'));
}
}
ProfilesController.php
<?php
namespace App\Http\Controllers;
use App\Profile;
use App\User;
use Illuminate\Http\Request;
use Intervention\Image\Facades\Image;
use Illuminate\Support\Facades\Cache;
class ProfilesController extends Controller
{
public function index(User $user)
{
$follows = (auth()->user()) ? auth()->user()->following->contains($user->id) : false;
$postCount = Cache::remember(
'count.posts.' . $user->id,
now()->addSeconds(30),
function () use ($user) {
return $user->posts->count();
});
$followersCount = Cache::remember(
'count.followers.' . $user->id,
now()->addSeconds(30),
function () use ($user) {
return $user->profile->followers->count();
});
$followingCount = Cache::remember(
'count.following.' . $user->id,
now()->addSeconds(30),
function () use ($user) {
return $user->following->count();
});
return view('profiles.index', compact('user', 'follows', 'postCount', 'followersCount', 'followingCount'));
}
//($user = (User::findOrFail($user));)
//('user' => $user)
//
public function edit(User $user)
{
$this->authorize('update', $user->profile);
return view('profiles.edit', compact('user'));
}
public function update(User $user)
{
$this->authorize('update', $user->profile);
$data = request()->validate([
'title' => 'required',
'description' => 'required',
'url' => 'url',
'image' => '',
]);
if (request('image')) {
$imagePath = request('image')->store('profile', 'public');
$image = Image::make(public_path("storage/{$imagePath}"))->fit(1000, 1000);
$image->save();
$imageArray = ['image' => $imagePath];
}
auth()->user()->profile->update(array_merge(
$data,
$imageArray ?? []
));
return redirect("/profile/{$user->id}");
}
public function show($user_id)
{
$user = User::find(1);
$user_profile = Profile::info($user_id)->first();
return view('profiles.show', compact('profile', 'user'));
}
public function profile()
{
return $this->hasOne('Profile');
}
}
Use asset helper function to get the uploaded image URL.
<img src="{{ asset('storage/' . $post->image) }}" class="w-100">
OR
<img src="{{ asset(Storage::url($post->image)) }}" class="w-100">
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();
}
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.
Basic Information
I' developing a simple Web Application using Laravel6.0.
And I made image post form at my create2.blade.php (blade file) file.
But my form seems to be having a routing Problem.
Problem
My Codes
routes/web.php
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('login');
Route::group(['middleweare' => 'auth'], function () {
Route::get('/', 'StoriesController#index');
Route::post('/', 'StoriesController#index');
Route::post('/stories/create', 'StoriesController#store');
Route::post('/stories/create', 'StoriesController#upload');
Route::get('/stories/create', 'StoriesController#add');
Route::post('/stories/create', 'StoriesController#add');
});
Route::group(['middleweare' => 'auth','name'=>'profile'], function () {
Route::get('/profile/edit', 'ProfileController#edit');
Route::get('/profile/create', 'ProfileController#add');
Route::post('/profile/create', 'ProfileController#add');
Route::post('/profile/create', 'ProfileController#store');
Route::post('/profile/create', 'ProfileController#upload');
});
Route::get('/home', 'HomeController#index')->name('home');
Auth::routes();
app/Http/Controllers/StoriesController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Story;
use Auth;
use App\Posts;
use App\History;
use App\Attachment;
use Carbon\Carbon;
use Storage;
class StoriesController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index(Request $request)
{
$images = Attachment::all();
return view('stories.index2', compact('images'));
}
public function add()
{
return view('stories.create2');
}
public function store(Request $request)
{
$d = new \DateTime();
$d->setTimeZone(new \DateTimeZone('Asia/Tokyo'));
$dir = $d->format('Y/m');
$path = sprintf('public/images/%s', $dir);
$data = $request->except('_token');
foreach ($data['images'] as $k => $v) {
$filename = '';
$attachments = Attachment::take(1)->orderBy('id', 'desc')->get();
foreach ($attachments as $attachment) {
$filename = $attachment->id + 1 . '_' . $v->getClientOriginalName();
}
unset($attachment);
if ($filename == false) {
$filename = 1 . '_' . $v->getClientOriginalName();
}
$v->storeAs($path, $filename);
$attachment_data = [
'path' => sprintf('images/%s/', $dir),
'name' => $filename
];
$a = new Attachment();
$a->fill($attachment_data)->save();
}
unset($k, $v);
return redirect('/');
}
public function upload(Request $request)
{
$this->validate($request, [
'file' => [
'required',
'file',
'image',
'mimes:jpeg,png',
]
]);
if ($request->file('file')->isValid([])) {
$path = $request->file->store('public');
return view('stories.index2')->with('filename', basename($path));
} else {
return redirect('/')
->back()
->withInput()
->withErrors();
}
}
}
resources/views/stories/create2.blade.php
#extends('layouts.front2')
#section('title','StoryCreate')
#section('content')
<link href="{{ asset('/css/main22.css' )}}" rel="stylesheet">
<div class="poststory">
<h1>Post Story</h1>
</div>
#if ($errors->any())
<ul>
#foreach($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
#endif
<form action="{{ url('/') }}" method="POST" enctype="multipart/form-data">
<div class="form">
<label for="photo" class="file">Choose Image or Video</label>
<div class="post">
<input type="file" class="here" name="images[]">
</div>
</div>
<br>
</div>
{{ csrf_field() }}
<div class="post">
<div class="btn postbtn">
<input type="submit" value="post" />
</div>
</div>
</form>
#endsection
resources/views/stories/index2.blade.php
#extends('layouts.front2')
#section('title','mainpage')
#section('content')
<div class="profile">
<div class="profileimg">
#foreach ($images as $image)
<img src="/storage/{{ $image->path . $image->name }}" style="height: 210px; width: 210px; border-radius: 50%;">
#endforeach
</div>
<div class="name">
#guest
<a class="nav-link2" href="{{ route('register')}}">{{ __('Create Accout!')}}</a>
#else
<a id="navbarDropdown" class="nav-link2" href="#" role="button">
{{Auth::user()->name}}<span class="caret"></span></a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
#csrf
</form>
</div>
#endguest
<div class="aboutme">
You can write your profile here!You can write your profile here!You can write your profile here!
You can write your profile here!You can write your profile here!You can write your profile here!
You can write your profile here!You can write your profile here!You can write your profile here!
You can write your profile here!You can write your profile here!You can write your profile here!
You can write your profile here!You can write your profile here!You can write your profile here!
</div>
</div>
<div class="new">
<div class="newtitle">
<h1>New</h1>
</div>
<div class="container1">
#foreach ($images as $image)
<img src="/storage/{{ $image->path . $image->name }}" class="images" style="height: 150px; width: 150px; border-radius: 50%;">
#endforeach
<div class="more">
more...
</div>
</div>
</div>
<div class="stories">
<div class="titlestories">
<h1>Stories</h1>
</div>
<div class="container2">
<div class="titleclose">
<h2>#CloseFriends</h2>
</div>
#foreach ($images as $image)
<img src="/storage/{{ $image->path . $image->name }}" class="images" style="height: 150px; width: 150px; border-radius: 50%;">
#endforeach
<div class="titlefollow">
<h2>#Follows</h2>
</div>
</div>
</div>
{{ csrf_field() }}
#endsection
What I tried.
I cleared the caches using this command,
$php artisan route: clear
and I' made a new cache using
$composer dump-autoload
$php artisan clear-compiled
$php artisan optimize
$php artisan config:cache
and I update my composer using this command
$composer update
but nothing has changed.
Sorry for my terrible English.
Waiting your comments and Answers!
You are submitting your from to {{ url('/') }} using POST method that means it is submitting as a POST to / route and your / route is defined by GET method in your web.php that is why you are getting this error
<form action="{{ url('/') }}" method="POST" enctype="multipart/form-data">
Route::get('/', 'StoriesController#index');
I am trying to add and display a image from mysql database stored in BLOB type in my web App, but while using {{ Auth::user()->profile_pic }} getting errors, can someone tell me what mistake i am doing and how to do this using laravel 5.
dashboard.blade.php
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row">
<div class="col-md-3">
<div class="panel panel-default">
<div class="panel-heading">Profile</div>
<div class="panel-body">
<img src="{{ Auth::user()->profile_pic }}" class="img-circle" width="200" height="200">
<h3>{{ Auth::user()->name }}</h3>
<h5>{{ Auth::user()->email }}</h5>
<hr>
<h6>{{ Auth::user()->created_at }}</h6>
</div>
</div>
</div>
<div class="col-md-9">
</div>
</div>
</div>
#endsection
The html <img src="{{ Auth::user()->profile_pic }}" class="img-circle" width="200" height="200"> needs address url instead of {{ Auth::user()->profile_pic }}
Add code in route first get the address using response object
Route::get('/' function($user) {
$Image = Auth::user()->profile_pic;
return response($Image)->header('Content-Type', 'image/jpeg');
}
then now pass address of response to the html element
Route::get('/dashboard', function() {
$id = Auth::user()->id;
$Image_url = "user/$id/profile-pic";
return view('/dashboard', ['Image_url' => $Image_url]);
}
Passing address in blade
<img src="{{ $Image_url }}" class="img-circle" width="200" height="200">