I am using laravel calendar with Carbon to show a daily promotion image.
I set the image in the calendar and it shows on the homepage. This part I am happy with.
The issue is if there is no promotion image set in the database, it is not showing a default image /image/promotion.jpg.
This is my controller code:
$setting = PromotionSetting::where('start_date', '<=', Carbon::now())->where('end_date', '>=', Carbon::now())->where('business_id', $business->id)->first();
$promotion = BusinessPromotion::find($setting->promotion_id);
This is the code on the homepage:
<div class="business_promotion text-center mt-3">
#if(isset($promotion))
<img src="{{ $promotion->path }}" width="350px" class="promotion-img">
#else
<img src="/images/promotion.jpg" width="350px" class="promotion-img">
#endif
</div>
Hope someone can help.
Thanks in advance.
Check the $promotion->path image in isset()
<div class="business_promotion text-center mt-3">
#if(isset($promotion->path))
<img src="{{ $promotion->path }}" width="350px" class="promotion-img">
#else
<img src="/images/promotion.jpg" width="350px" class="promotion-img">
#endif
</div>
You ask if isset(). It is set. It just happens to be null (probably).
Best changing the check to something like:
#if(!is_null($promotion) && isset($promotion->path))
If that still doesn't work, you can force it null if it doesn't find the promotion like this:
$promotion = BusinessPromotion::find($setting->promotion_id) ?: null;
Then it should work. Let me know how you get on!
Related
i am trying to show the image of the admin user but no thing show .
. and name email of the user showing correctly
#php
$adminData = Auth::user();
#endphp
< div class="widget-user-header bg-black" >
<h3 class="widget-user-username">Admin Name : {{ $adminData->name }}</h3>
Edit Prfile
<h6 class="widget-user-desc">Email : {{ $adminData->email }}</h6>
</div>
<div class="widget-user-image">
<img class="rounded-circle" src="{{(!empty(asset($adminData->profile_photo_path) ))? url('upload/admin_images/'.$adminData->profile_photo_path):url('upload/no_image.jpg')}}">
</div>
You have to use like below
#if($adminData->profile_photo_path)
<img class="rounded-circle" src="{{url('/'.$adminData->profile_photo_path)}}">
#else
<img class="rounded-circle" src="{{url('/no_image.jpg')}}">
#endif
You Can check if admin photo contains null value or not
<img class="rounded-circle" src="{{$adminData->profile_photo_path != null? url('upload/admin_images/'.$adminData->profile_photo_path):url('upload/no_image.jpg')}}">
Let's do it like this. Make sure you have a default image like no_image.jpg as a fallback function. It does display the image in case if the profile_photo_path attr exists or falls into no_image if not. However, I think your issue is because you don't point to storage folder.
<img src="{{ storage_path($adminData->profile_photo_path ?? 'admin_images/no_image.jpg')) }}" />
I have a database with images related to one product, and I'd like to take those images there only from the second one.
The code to my view is this. I put a line for each image
#foreach($allImages as $image)
<img src="{{ asset('merchants/images/products/' . $image->image) }}" alt="little picture">
#endforeach
I hope I'm clear enough on what I'd like to do...
#foreach($allImages->skip(1) as $image)
<img src="{{ asset('merchants/images/products/' . $image->image) }}" alt="little picture">
#endforeach
This will skip the first record
You can do something like this to skip the first image in the array
#foreach($allImages as $image)
#if($loop->first){
#continue;
}
else{
<img src="{{ asset('merchants/images/products/' . $image->image) }}" alt="little picture">
}
#endforeach
I hope it is helpful for you
I have been learning "code" just over a year for a project i have and have got stuck on a particular function that i am trying to create for the user. I have lots of divs with different information being rendered from a database. Html and css looks great I have then created blade #sections to hold the info but struggling to add functionality.
#foreach($canal as $canal)
#section('water-left')
<img class="img-responsive" src="{{ asset('images/canals/' . $canal->image)}}">
#section('location')
<strong class="words myh4">{{$canal->name}}</strong>
#section('water-right')
<img class="img-responsive" src="{{ asset('images/canals/' . $canal->image)}}">
#endsection
#endsection
#endsection
#endforeach
I have paginated contents of database to 3 and am trying to attatch the id1 image to ('water-left'), the id2 name to ('location') and id3 image to('water-right') currently i get just id1 in all sections any help please my controller looks like this
public function getcanalimage()
{
$canal = Canal::paginate(3);
return view('waters.canal_fishing',compact('canal'));
}
any help would be much appreciated thanks.
Try to use foreach loop, because $canal is array with more one values and you need use a loop to show all them:
#section('water-right')
#foreach($canal as $item)
<img class="img-responsive" src="{{ asset('images/canals/' . $item->image)}}">
#endforeach
#endsection
It has been a while since the question was posted but, for anyone using Laravel 5.8, there seems to be an undocumented blade tag/directive called #overwrite.
So replacing #endsection with #overwrite should do the work.
#foreach($canal as $item)
#section('water-left')
<img class="img-responsive" src="{{ asset('images/canals/' . $canal->image)}}">
#section('location')
<strong class="words myh4">{{$item->name}}</strong>
#section('water-right')
<img class="img-responsive" src="{{ asset('images/canals/' . $item->image)}}">
#overwrite
#overwrite
#overwrite
#endforeach
I am working on the laravel 5.0. I am getting an error: "trying to get property of non-object".I want to get an image on the desired page by clicking on that particular image. There are so many images on the page, i just want after clicking on any image, it will be appear on the desired page.
here is my code:
My Routes:
Route::get('/image/big/{id}' ,[
'uses'=>'GalleryController#bigimage',
'as'=>'bigimage'
]);
My controller:
public function bigimage($id){
$images=image::findorFail($id);
return view('bigimage' , ['images'=>$images]);
}
My view from where i am calling the required Route:
#foreach($gallery->images as $image)
<li>
<a href="{{ URL('/image/big/'.$image->id) }}">
<img id="jumboimage2" src="{{ url($image->file_path) }}"></a>
</li>
<li>
<a href="{{ URL('/image/delete/'.$image->id) }}" id="margin">
<span id="margin" class="glyphicon glyphicon-remove-sign"></span></a>
</li>
#endforeach
My view where i want to get the required image:
<div class="row">
<section class="col-md-3">
#foreach($images as $image)
{{$image->id}}
#endforeach
</section>
</div>
try this one out
$image = image::findOrFail($id);
return view('bigimage' , ['image' => $image])
$images=image::findorFail($id); should be $images=image::findOrFail($id);.
findOrFail() returns a single model, i.e. one image, so I would have:
$image = image::findOrFail($id);
return view('bigimage' , ['image' => $image]);
You don't show where image:: comes from, however usually this is from a facade so is Image:: with a capital.
The view would then not have the #foreach loop as you'd only have a single image.
<div class="row">
<section class="col-md-3">
{{$image->id}}
</section>
</div>
You also need to elaborate on this to get from the id to an image but I'm assuming that's just not shown.
If you were able to give some detail about which line is causing the error this would make it easier to diagnose, as indicated by Maraboc there could be an issue with $gallery as well.
I'am doing a award system on my site, and I want to award badges to users who have been registered for a month, and then years on my website. How would I go of doing this in Laravel 5.2? I already have a created_at on my users table.
********** EDIT *****************
Ok so i need to display that in the view, similar to this:
#if ($user->difference <= 30)
<img src="{{ ShowSignedUpFor30days }}" class="ui small circular image" id="Badge">
#else
#endif
#if ($user->difference <= 30)
<img src="{{ ShowSignedUpFor300days }}" class="ui small circular image" id="Badge">
#else
#endif
As you see from your table you can use created_at field to find out when user is created.
You can create a function similar to this in your User model to create badges. (not tested)
public function userSinceInDays(){
$created = $this->created_at;
$now = Carbon::now();
$difference = $created->diff($now)->days;
return $difference;
}
You can access to
#if ($user->userSinceInDays() <= 30)
<img src="{{ ShowSignedUpFor30days }}" class="ui small circular image" id="Badge">
#endif
#if ($user->userSinceInDays() >= 300)
<img src="{{ ShowSignedUpFor300days }}" class="ui small circular image" id="Badge">
#endif