Convert Blade If Else to Vue If Else - laravel

I have an if else condition in Blade and I want to convert it to a Vue if else
#if (Auth::user()->avatar != null)
<img src="{{ URL::to('storage/app/public') . '/' . Auth::user()->avatar }}"
class="img-circle elevation-2" alt="User Image">
#endif
#if (Auth::user()->avatar == null)
#if (Auth::user()->gender == 'Male')
<img src="{{ URL::asset('public/bower_components/admin-lte/dist/img/fb-male.jpg') }}"
class="img-circle elevation-2" alt="User Image">
#else
<img src="{{ URL::asset('public/bower_components/admin-lte/dist/img/female-fb.jpg') }}"
class="img-circle elevation-2" alt="User Image">
#endif
#endif

To convert the #if branches in your blade file, use <template>s with v-if/v-else:
<template v-if="{{ Auth::user()->avatar != null }}">
<img src="{{ URL::to('storage/app/public') . '/' . Auth::user()->avatar }}"
class="img-circle elevation-2" alt="User Image">
</template>
<template v-else>
<template v-if="{{ Auth::user()->gender == 'Male' }}">
<img src="{{ URL::asset('public/bower_components/admin-lte/dist/img/fb-male.jpg') }}"
class="img-circle elevation-2" alt="User Image">
</template>
<template v-else>
<img src="{{ URL::asset('public/bower_components/admin-lte/dist/img/female-fb.jpg') }}"
class="img-circle elevation-2" alt="User Image">
</template>
</template>

Related

Uncaught TypeError: e is null in bootstrap album

I'm trying to create a bootstrap carousel album thumbnail.
My code is here...
<div class="col-lg-9 mb-3">
<div id="myCarousel" class="carousel slider d-flex justify-content-center" data-bs-ride="carousel">
<div class="carousel-inner">
#foreach($galleries as $gallery)
<div class="carousel-item {{ $loop->first ? 'active' : '' }}">
<img src="{{ asset('storage/'.$gallery->image) }}" class="img-fluid rounded" alt="{{ $product->title }}">
</div>
#endforeach
</div>
<ol class="carousel-indicators list-inline bottom-12">
#foreach($galleries as $gallery)
<li class="list-inline-item {{ $loop->first ? 'active' : '' }}">
<a id="carousel-selector-{{ $gallery->id }}" class="{{ $loop->first ? 'selected' : '' }}" data-bs-slide-to="{{ $gallery->id }}" data-bs-target="#myCarousel">
<img src="{{ asset('storage/'.$gallery->image) }}" class="img-fluid rounded" alt="{{ $product->title }}">
</a>
</li>
#endforeach
</ol>
</div>
</div>
But when I click on the carousel's indicators, I receive this error from bootstrap.min.js:
Now my question is what is wrong with my code/solution?

Split String to get an Array

In Database :- "["http://localhost//image/aeefb050911334869a7a5d9e4d0e1689.jpg","http://localhost//image/959776b99b006e5785c3a3364949ce47.jpg"]"
After Json_decode = ["http://localhost//image/aeefb050911334869a7a5d9e4d0e1689.jpg","http://localhost//image/959776b99b006e5785c3a3364949ce47.jpg"]
Output i Want:- [0] - http://localhost//image/aeefb050911334869a7a5d9e4d0e1689.jpg
[1] - http://localhost//image/959776b99b006e5785c3a3364949ce47.jpg
Code:-
#if(is_array(json_decode($data->item_image)))
#php $image = json_decode($data->item_image);
#endphp
#foreach($image as $key=>$row)
#if($key == 0)
<div class='carousel-item active'>
<!-- <img class='img-size img-responsive' src="{{ asset('image/'. $row) }}" /> -->
<img class='img-size img-responsive' src="{{ $row }}" />
</div>
#else
<div class='carousel-item'>
<!-- <img class='img-size' src="{{ asset('image/'. $row) }}" /> -->
<img class='img-size' src="{{ $row }}" />
</div>
#endif
#endforeach
#else
#endif
you can use this
$str = '["http://localhost//image/aeefb050911334869a7a5d9e4d0e1689.jpg",
"http://localhost//image/959776b99b006e5785c3a3364949ce47.jpg"]';
eval("\$myarray = $str;");
print_r($myarray);
#if(json_decode($data->item_image) != '')
#php $image = json_decode($data->item_image);
eval("\$myarray = $image;");
#endphp
#foreach($myarray as $key=>$row)
#if($key == 0)
<div class='carousel-item active'>
<!-- <img class='img-size img-responsive' src="{{ asset('image/'. $row) }}" /> -->
<img class='img-size img-responsive' src="{{ $row }}" />
</div>
#else
<div class='carousel-item'>
<!-- <img class='img-size' src="{{ asset('image/'. $row) }}" /> -->
<img class='img-size' src="{{ $row }}" />
</div>
#endif
#endforeach
#else
#endif

Route [product/products] not defined. (View:

hi m trying to get products related to that category from index page but it shows error, whole of these things are working fine at admin side but not at user side,
index.blade.php:
#foreach($categories as $category)
<div class="col-sm-10 col-md-8 col-lg-4 m-l-r-auto">
<!-- block1 -->
<div class="block1 hov-img-zoom pos-relative m-b-30">
<img src="{{ URL::to('/') }}/images/backend_images/category_images/{{ $category->category_image }}" class="img-thumbnail" style="width: 370px; height: 448px;" />
<div class="block1-wrapbtn w-size2">
<!-- Button -->
<a href="{{ route('product/products', $category->id) }}" class="flex-c-m size2 m-text2 bg3 hov1 trans-0-4">
{{ ucwords($category->category_name) }}
</a>
</div>
</div>
</div>
#endforeach
routes:
Route::get('/product/{id}','ProductController#products');
route:list
paste.ofcode.org/Yw3CU2MXdCQXpxh9H3vKYh
A better way to do this is to define your route with a name like this:
Route ::get('/product/{id}','ProductController#products')->name('product.products');
Then specify your link like this:
<a href="{{ route('product.products', $category->id) }}" class="flex-c-m size2 m-text2 bg3 hov1 trans-0-4">
{{ ucwords($category->category_name) }}
</a>
Change this:
<a href="{{ route('product/products', $category->id) }}" class="flex-c-m size2 m-text2 bg3 hov1 trans-0-4">
{{ ucwords($category->category_name) }}
</a>
To this:
<a href="{{ route('admin.product.show', $category->id) }}" class="flex-c-m size2 m-text2 bg3 hov1 trans-0-4">
{{ ucwords($category->category_name) }}
</a>

Dompf load forever laravel 4.2

Im using dompf trying to generate a pdf and save it to the storage folder and a database, the problem is when i try to generate the pdf, it never load, when i use the sample code in github it work, it shows "test", but when i try to load a view it takes forever. this is the code i'm using
$pdf = PDF::loadView('emails.myView',$myData);
return $pdf->stream();
I have tried using the download and the save methods, but doens't work and the page load forever but the pdf is never generated.
and the view just show 4 or 6 elements with 1 main call $hist, returning the view is rendered without problems.
<style type="text/css">
Bunch of css.
</style>
<table class="center-block">
<tr>
<td colspan="3">
<img src="{{ asset('images/boletin/btn_cabeza.jpg') }}" class="img-responsive center-block">
</td>
</tr>
<tr>
<td rowspan="4" class="aside">
<a href="{{ URL::to('contacto/donaciones') }}">
<img src="{{ asset('images/boletin/btn_dona.jpg') }}" class="img-responsive center-block" >
</a>
<div class="social-container">
<h3>Siguenos en:</h3>
<hr>
<ul>
<li><i class="fa fa-twitter"></i></li>
<li><i class="fa fa-instagram"></i></li>
<li><i class="fa fa-facebook"></i></li>
<li><i class="fa fa-youtube-play"></i></li>
</ul>
</div>
<h2 class="text-blue">Historias Epékeinas</h2>
<br>
#if(count($hist->imagenes) > 0)
<img src="{{ asset('images/news/'.$hist->imagenes->first()->image) }}" class="img-responsive img-boletin" alt="{{ $hist->titles->first()->text }}">
#endif
<div class="bg-green padding-20">
<h2 class="boletin-title">
{{ $hist->titles->first()->text }}
#if(!is_null($hist->subtitle))
{{ $hist->subtitle->titles->first()->text }}
#endif
</h2>
</div>
<hr>
<div class="text-justify">
{{ substr(strip_tags($hist->descriptions->first()->text), 0, 1600) }}[...]
<br>
Leer más
</div>
</td>
</tr>
<?php $k = 0;?>
#foreach($article as $a)
#if($k == 0 || $k%2 == 0)
<tr>
#endif
#if(!empty($principal))
#if($a->slugs->first()->text != $principal->id)
<td class="news fixedHeight bg-{{ $colors[$j] }}">
#if(count($a->imagenes) > 0)
<img src="{{ asset('images/news/'.$a->imagenes->first()->image) }}" class="img-responsive center-block img-boletin" alt="{{ $a->titles->first()->text }}">
#else
<img src="{{ asset('images/logo.png') }}" class="img-responsive center-block img-boletin" alt="{{ $a->titles->first()->text }}">
#endif
<h2 class="boletin-title">{{ $a->titles->first()->text }}</h2>
<p class="text-justify">{{ substr(strip_tags($a->descriptions->first()->text), 0, 300) }} [...]</p>
<a target="_blank" href="{{ URL::to('noticias/'.$a->slugs->first()->text) }}" class="btn btn-default btn-xs pull-right">Leer más</a>
<div class="clearfix"></div>
</td>
<?php $k++; ?>
#endif
#else
<td class="news fixedHeight bg-{{ $colors[$j] }}">
#if(count($a->imagenes) > 0)
<img src="{{ asset('images/news/'.$a->imagenes->first()->image) }}" class="img-responsive center-block img-boletin" alt="{{ $a->titles->first()->text }}">
#else
<img src="{{ asset('images/logo.png') }}" class="img-responsive center-block img-boletin" alt="{{ $a->titles->first()->text }}">
#endif
<h2 class="boletin-title">{{ $a->titles->first()->text }}</h2>
<p class="text-justify">{{ substr(strip_tags($a->descriptions->first()->text), 0, 300) }} [...]</p>
<a target="_blank" href="{{ URL::to('noticias/'.$a->slugs->first()->text) }}" class="btn btn-default btn-xs pull-right">Leer más</a>
<div class="clearfix"></div>
</td>
<?php $k++; ?>
#endif
<?php $j++; ?>
#if($j == 4)
<?php $j=0; ?>
#endif
#if(($k != 0 && $k%2 == 0) || $k == count($article))
</tr>
#endif
#endforeach
<tr>
<td colspan="3" class="text-center">
<h3>© Derechos Reservados Funda Epékeina 2016.</h3>
</td>
</tr>
</table>
<div class="container center-block">
<div class="bg-square bg-blue"></div>
<div class="bg-square bg-yellow"></div>
<div class="bg-square bg-green"></div>
<div class="bg-square bg-pink"></div>
</div>
<div class="clearfix"></div>
what could be wrong? is there any other choice for generating pdf.
Check those points in order:
For Laravel 4.* I suggest you to use this DOMPDF wrapper https://github.com/barryvdh/laravel-dompdf/tree/0.4
Maybe your view is trying to render content out of the page, try to add dinamic page break, you can do so by styling an element with page-break-before: always; or page-break-after: always.; Try to delete the foreach and adding 1 or 2 static element rendering it in one page
Check for errors in the view by rendering it in html with return View::make('emails.myView',$myData)->render();.
Check php and html sintax, dompdf doesn't work if some html tags are
not well closed
Consider to use Knp-snappy library for Laravel https://github.com/barryvdh/laravel-snappy/tree/0.1

Displaying feeds and blogs according to the created time

I'm having a home page where all the feeds along with comments and blogs are being displayed. Right now it is showing first all the feeds and then the blog. But I want it should be displayed according to the created time, mixer of feeds and blog not like first feed will come and then the blog. Can anyone tell me how to acheive that. This is my index.blade.php
#extends('layouts/default')
{{-- Page title --}}
#section('title')
Home
#parent
#stop
{{-- page level styles --}}
#section('header_styles')
<!--page level css starts-->
<link rel="stylesheet" type="text/css" href="{{ asset('assets/css/frontend/action.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('assets/css/frontend/tabbular.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('assets/css/frontend/jquery.circliful.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('assets/vendors/owl.carousel/css/owl.carousel.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('assets/vendors/owl.carousel/css/owl.theme.css') }}">
<!--end of page level css-->
#stop
{{-- content --}}
#section('content')
<div class="row">
<div class="column col-md-1 col-xs-1 col-sm-1"></div>
<div class="column col-md-3 col-xs-3 col-sm-3"><!--gm-editable-region--> </div>
<div class="column col-md-4 col-xs-4 col-sm-4">
#include ('action.partials.form')
#include ('action.partials.error')
#include ('action.partials.feed')
#include ('action.partials.blogfeed')
</div>
<div class="column col-md-3 col-xs-3 col-sm-3"><!--gm-editable-region--></div>
<div class="column col-md-1 col-xs-1 col-sm-1"></div>
#stop
{{-- footer scripts --}}
#section('footer_scripts')
<!-- page level js starts-->
<script type="text/javascript" src="{{ asset('assets/js/frontend/jquery.circliful.js') }}"></script>
<script type="text/javascript" src="{{ asset('assets/vendors/owl.carousel/js/owl.carousel.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('assets/js/frontend/carousel.js') }}"></script>
<script type="text/javascript" src="{{ asset('assets/js/frontend/index.js') }}"></script>
<!--page level js ends-->
#stop
This is action.partials.feed
#foreach($feeds as $feed)
<article class="media">
<div class="well">
<div class="pull-left">
<img class="profile" src="{{ URL::to('/uploads/users/'.$feed->user->pic) }}" class="img-responsive" alt="Image" style="width:48px;height:48px;padding-right : 10px;padding-bottom: 5px;">
</div>
<strong>{{ $feed->user->first_name }}
{{ $feed->user->last_name }}
<small> posted </small>
</strong>
{{ $feed->created_at->diffForHumans() }}<br><hr>
{{ $feed->feed_content }}
<hr>
{!! Form::open(['url' => 'home/{storecomment}']) !!}
<div><input type="hidden" name="feed_id" value="{{ $feed->feed_id }}" /></div>
<div class="form-group">
{!! Form::text('comment', null, ['class'=>'form-control', 'rows'=>3, 'placeholder'=>"Comment"]) !!}
</div>
<div class="form-group feed_post_submit">
{!! Form::submit('Comment', ['class' => 'btn btn-default btn-xs']) !!}
</div>
{!! Form::close() !!}
#foreach($feed->comments as $comment)
<div class="pull-left">
<img class="profile" src="{{ URL::to('/uploads/users/'. $comment->user->pic) }}" class="img-responsive" alt="Image" style="width:48px;height:48px;padding-right : 10px;padding-bottom: 5px;">
</div>
{{ $comment->user->first_name }}
{{ $comment->created_at->diffForHumans() }}
{{ $comment->comment }}<hr>
#endforeach
</div>
</article>
#endforeach
action.partials.blogfeed
#foreach($blogs as $blog)
<article class="media">
<div class="well">
<div class="pull-left">
<img class="media-object" src="{{ URL::to('/uploads/users/'.$blog->user->pic) }}" class="img-responsive" alt="Image" style="width:48px;height:48px;padding-right : 10px;padding-bottom: 5px;">
</div>
<strong>{{ $blog->user->first_name }}
{{ $blog->user->last_name }}
<small> posted blog</small>
</strong>
{{ $blog->created_at->diffForHumans() }}<br><hr>
<h4>{{ $blog->title }}</h4>
<div class="featured-post-wide thumbnail">
#if($blog->image)
<img src="{{ URL::to('/uploads/blog/'.$blog->image) }}" class="img-responsive" alt="Image">
#endif
</div>
</div>
</article>
#endforeach
This is my feedcontroller
<?php
namespace App\Http\Controllers;
use Request;
use Auth;
use Sentinel;
use App\Feed;
use App\Http\Requests;
use App\Blog;
use App\Http\Controllers\Controller;
use App\Comment;
class FeedsController extends Controller
{
public function index() {
// $comments = Comment::latest()->get();
$feeds = Feed::with('comments', 'user')->where('user_id', Sentinel::getUser()->id)->latest()->get();
$blogs = Blog::latest()->simplePaginate(5);
$blogs->setPath('blog');
return view('action.index', compact('feeds', 'blogs'));
}
public function store(Requests\CreateFeedRequest $request)
{
$request->merge( [ 'user_id' => Sentinel::getuser()->id] );
Feed::create($request->all());
return redirect('home');
}
public function storecomment(Requests\CommentRequest $request, Feed $feed)
{
$comment = new Comment;
$comment->user_id =Sentinel::getuser()->id;
$comment->feed_id = $request->feed_id;
$comment->comment = $request->comment;
$comment->save();
return redirect('/home');
}
}
Can any one tell me how to display feeds and blogs according to the published time.
In your controller index method, try something like this:
public function index() {
// $feeds = Feed::with('comments', 'user')->where('user_id', Sentinel::getUser()->id)->latest()->get();
// $blogs = Blog::latest()->simplePaginate(5);
// $blogs->setPath('blog');
$feeds = Feed::with('comments', 'user')->where('user_id', Sentinel::getUser()->id)->latest()->get();
$blogs = Blog::latest()->paginate(5);
$feeds = $feeds->merge($blogs)->sortByDesc('created_at');
return view('action.index', compact('feeds'));
}
The biggest problem you're going to have is that your Feed object is likely different than your Blog object. Meaning each will have unique column names that the other doesn't have. This is going to make doing the foreach a bit of a mess...
Remove #include ('action.partials.blogfeed'). This is not longer relevant for us.
In action.partials.feed...we'll output it all (hopefully without too many "hacks" and conditionals):
#foreach($feeds as $feed)
<article class="media">
<div class="well">
<div class="pull-left">
<img class="profile" src="{{ URL::to('/uploads/users/'.$feed->user->pic) }}" class="img-responsive" alt="Image" style="width:48px;height:48px;padding-right : 10px;padding-bottom: 5px;">
</div>
<strong>
{{ $feed->user->first_name }}
{{ $feed->user->last_name }}
<small> posted </small>
</strong>
// We'll use #if(isset($feed->title)) to check if it's a blog post, aka ugly hack.
#if(isset($feed->title))
{{ $blog->created_at->diffForHumans() }}
<br><hr>
<h4>{{ $blog->title }}</h4>
<div class="featured-post-wide thumbnail">
#if($blog->image)
<img src="{{ URL::to('/uploads/blog/'.$blog->image) }}" class="img-responsive" alt="Image">
#endif
</div>
#else
{{ $feed->created_at->diffForHumans() }}<br><hr>
{{ $feed->feed_content }}
<hr>
{!! Form::open(['url' => 'home/{storecomment}']) !!}
<div><input type="hidden" name="feed_id" value="{{ $feed->feed_id }}" /></div>
<div class="form-group">
{!! Form::text('comment', null, ['class'=>'form-control', 'rows'=>3, 'placeholder'=>"Comment"]) !!}
</div>
<div class="form-group feed_post_submit">
{!! Form::submit('Comment', ['class' => 'btn btn-default btn-xs']) !!}
</div>
{!! Form::close() !!}
#foreach($feed->comments as $comment)
<div class="pull-left">
<img class="profile" src="{{ URL::to('/uploads/users/'. $comment->user->pic) }}" class="img-responsive" alt="Image" style="width:48px;height:48px;padding-right : 10px;padding-bottom: 5px;">
</div>
{{ $comment->user->first_name }}
{{ $comment->created_at->diffForHumans() }}
{{ $comment->comment }}<hr>
#endforeach
#endif
</div>
</article>
#endforeach
Because Illuminate\Database\Eloquent extends Illuminate\Support\Collection, we can easily merge them together. Because both $feeds and $blogs are an Eloquent Collection, we can easily merge them into one collection:
$feeds_and_blogs = collect($feeds->toArray(), $blogs->toArray());
Now you will have a combination of both. Because you've used $table->timestamps() in your migration to get your columns, we can easily perform a comparison against the created_at timestamp to get the sorting that you want:
$sorted_feeds_and_blogs = $feeds_and_blogs->sortBy(function($item){
return $item->created_at;
});
However, you likely want them to be sorted by newest first. Thankfully, collections have a sortByDesc function which will do exactly what we want.
Although in the grand scheme of things you probably really want a Polymorphic relationship.

Resources