The laravel paginator does work, but not good in my case.
So I have a forum with comments and the paginator must display when there are more than 10 comments on that page.
So I have a topic that has more than 10 comments and then it works fine on that page, but when I go to another page, he does take the pagination of the most comments. That is not what I want.
Here are some screens and code:
Here are there more than 10 comments, so it is good that it displays the paginator. The strange thing here is that it only shows 2 comments and not 10.
Here is another topic with just 8 comments, so the pagination shouldn't display anything:
But as you can see, it does show the paginator....
My code look like this:
Controller:
public function thread($title)
{
$thread = Thread::where('title', '=', str_replace('Thread-', '',str_replace('-', ' ', $title)))->first();
$usercolor = DB::table('threads')
->join('user', 'threads.uid', '=', 'user.id')
->join('role', 'user.role_id', '=', 'role.id')
->where('threads.uid', '=', $thread->uid)
->first();
$usertitle = DB::table('threads')
->join('user', 'threads.uid', '=', 'user.id')
->where('threads.uid', '=', $thread->uid)
->first();
$comments = Comment::orderBy('posted_at', 'asc')
->where('deleted_at', '=', '0000-00-00 00:00:00')
->with('user.role')
->paginate(10);
if (!$thread) {
return die('bestaat niet!');
}else{
return View::make('thread')->with('threads', $thread)
->with('comments', $comments)
->with('usercolor', $usercolor)
->with('usertitle', $usertitle);
}
}
View:
#include('globs.header')
<div class="col-sm-offset-1 col-sm-10">
<div class="clearfix"> </div>
#if(Request::get('page', 1) == 1)
<div class="panel panel-default" id="a9">
<div class="panel-heading">
<div class="panel-title">{{ $threads->title }}
</div>
</div>
<div class="panel-body thread-row">
<div class="row thread-row">
<div class="col-md-2 col-sm-3 text-center userblock">
<div class="clerafix"> </div>
<img class="img-thumbnail avatar" src="./public/img/avatar.jpg" alt="Avatar" height="55px;" width="55px">
<div class="push_bottom_5" style="color:{{ $usercolor->colour }};"><strong>{{ $threads->username }}</strong></div>
<div class="push_bottom_5"><small>{{ $usertitle->usertitle }}</small></div>
<div class="label label-default" style="background-color:{{ $usercolor->colour }};">{{ $usercolor->name }}</div>
<div class="push_bottom_5">
#if($usercolor->id == '1')
<i class="fa fa-star"></i>
#elseif($usercolor->id == '2')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#elseif($usercolor->id == '3')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#elseif($usercolor->id == '4')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#elseif($usercolor->id == '5')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#elseif($usercolor->id >= '6')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#endif
</div>
<div class="text-muted text-left"><small>Total Posts: 66</small></div>
<div class="text-muted text-left"><small>Joined 05-11-2014</small></div>
<div class="clerafix"> </div>
</div>
<div class="col-md-5 col-sm-6 col-xs-8">
<div class="clerafix"> </div>
<div class="text-muted"><span><i class="fa fa-calendar"></i> </span><small>
<span>Posted:</span> {{ date("d-m-Y", strtotime($threads->date_posted)) }}</small></div>
</div>
<div class="col-md-10 col-sm-9 col-xs-12">
<div class="clerafix"> </div>
<div class="content_body"><p>{{ Helper::Filter(BBCode::parse($threads->message)) }}</p>
</div>
<div class="clerafix"> </div>
</div>
</div>
</div>
<div class="panel-footer clearfix">
<div class="pull-right">
<!-- acties -->
<button class="btn btn-primary btn-sm"><i class="fa fa-edit"></i> Aanpassen</button>
<button class="btn btn-primary btn-sm"><i class="fa fa-quote-left"></i> Quote</button>
<button class="btn btn-danger btn-sm"><i class="fa fa-trash"></i> Verwijder</button>
<button class="btn btn-warning btn-sm"><i class="fa fa-exclamation"></i> Rapporteer</button>
</div>
</div>
</div>
<!-- end of the topic -->
</div>
#endif
<!-- begin of comments -->
#foreach($comments as $comment)
#if($comment->tid == $threads->tid)
<div class="col-sm-offset-1 col-sm-10">
<div class="clearfix"> </div>
<div class="panel panel-default" id="a9">
<div class="panel-body thread-row">
<div class="row thread-row">
<div class="col-md-2 col-sm-3 text-center userblock">
<div class="clerafix"> </div>
<img class="img-thumbnail avatar" src="./public/img/avatar.jpg" alt="Avatar" height="55px;" width="55px">
<div class="push_bottom_5" style="color:{{ $comment->user->role->colour }};"><strong>{{ $comment->username }}</strong></div>
<div class="push_bottom_5"><small>{{ $comment->user->usertitle }}</small></div>
<div class="label label-default" style="background-color:{{ $comment->user->role->colour }};">{{ $comment->user->role->name }}</div>
<div class="push_bottom_5">
#if($comment->user->role->id == '1')
<i class="fa fa-star"></i>
#elseif($comment->user->role->id == '2')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#elseif($comment->user->role->id == '3')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#elseif($comment->user->role->id == '4')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#elseif($comment->user->role->id == '5')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#elseif($comment->user->role->id >= '6')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#endif
</div>
<div class="text-muted text-left"><small>Total Posts: 66</small></div>
<div class="text-muted text-left"><small>Joined 05-11-2014</small></div>
<div class="clerafix"> </div>
</div>
<div class="col-md-5 col-sm-6 col-xs-8">
<div class="clerafix"> </div>
<div class="text-muted"><span class="hidden-md "><i class="fa fa-calendar"></i>
</span><small><span>Posted:</span> {{ date("d-m-Y", strtotime($comment->posted_at)) }}</small></div>
</div>
<div class="col-md-10 col-sm-9 col-xs-12">
<div class="clerafix"> </div>
<div class="content_body"><p>{{ Helper::Filter(BBCode::parse($comment->comment)) }}</p>
</div>
<div class="clerafix"> </div>
</div>
</div>
</div>
<div class="panel-footer clearfix">
<div class="pull-right">
<!-- acties -->
<button class="btn btn-primary btn-sm"><i class="fa fa-edit"></i> Aanpassen</button>
<button class="btn btn-primary btn-sm"><i class="fa fa-quote-left"></i> Quote</button>
<button class="btn btn-danger btn-sm"><i class="fa fa-trash"></i> Verwijder</button>
<button class="btn btn-warning btn-sm"><i class="fa fa-exclamation"></i> Rapporteer</button>
</div>
</div>
</div>
</div>
#endif
#endforeach
<!-- end of comments -->
#if(Auth::check())
<div class="col-sm-offset-1 col-sm-10">
<div class="clearfix"> </div>
<div class="panel panel-default" id="a9">
<div class="panel-heading"><h4>Snelle reactie plaatsen</h4></div>
<div class="panel-body">
{{ Form::open(array('url' => 'SubmitComment')) }}
<input type="hidden" value="{{ $threads->tid }}" name="tid">
{{ Honeypot::generate('spamprt', 'time') }}
<textarea name="comment" class="form-control" col="250" rows="5" placeholder="Typ uw bericht..."></textarea>
<div class="clearfix"> </div>
<button class="btn btn-success pull-left" type="submit" name="action">
Reageer
</button>
{{ Form::close() }}
</div>
</div>
</div>
#endif
<div class="col-md-4 col-md-offset-5">{{ $comments->links() }}</div>
</div>
</div>
#include('globs.footer')
I hope you guys will understand my problem and are be able to find a perfect solution with me.
It looks like you always retrieve all comments. I can also see this in your template, where you wrap your code in #if($comment->tid == $threads->tid) within your foreach.
This means that later in your template, where you retrieve the pagination links, it will retrieve the links for all comments, but not all comments are shown in the page, since you filter them manually in the loop.
Query the comments like
$comments = Comment::orderBy('posted_at', 'asc')
->where('deleted_at', '=', '0000-00-00 00:00:00')
->where('tid', $threads->tid) // it's about this line!
->with('user.role')
->paginate(10);
Note:
Above should provide a solution for your problem, but as an extra, you could also look into relationships. As an addition, this answer on SO "Laravel 4.1: How to paginate eloquent eager relationship?" (Since you tagged your post with Laravel-4) has some nice arguments on how to approach this efficiently.
Related
I am working on a Laravel project and I want to display currently authenticated users posts in view file, I am getting an error while trying to achieve that says
"Class name must be a valid object or a string"...
my blade view
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div id="accordion">
<div class="card">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<i class="fa fa-product-hunt" aria-hidden="true"></i> Swap
</button>
</h5>
</div>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
#foreach($data as $dat)
<div class="card mb-3" style="max-width: 540px;">
<div class="row g-0">
<div class="col-md-4">
<img
src="{{asset('images/' . $dat->imogi)}}"
alt="Trendy Pants and Shoes"
/>
</div>
<div class="col-md-8">
<div class="card-body">
<div style="text-align: right;">
<small style="color:#3490dc;">{{$dat->organazation}}</small> <small><i class="fa fa-calendar" style="color:#3490dc" aria-hidden="true"></i> {{ $dat->created_at->format('d/m/Y') }}</small>
</div>
<h5 class="card-title"><i class="fa fa-user-circle-o" style="color:#3490dc" aria-hidden="true"></i> {{$dat->name}}</h5>
<small><i class="fa fa-map-marker" style="color:#3490dc" aria-hidden="true"></i> {{$dat->location}}</small> | <small><i class="fa fa-phone" style="color:#3490dc" aria-hidden="true"></i>{{$dat->contact}}</small>
<hr/>
<p class="card-text">
<b>{{$dat->title}}</b>
</p>
<small style="color:#3490dc;">M{{$dat->price}}</small>
<p class="card-text">
{{$dat->message}}
</p>
</div>
</div>
</div>
</div>
<br/>
#endforeach
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingTwo">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
<i class="fa fa-product-hunt" aria-hidden="true"></i> Work
</button>
</h5>
</div>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordion">
<div class="card-body">
<form class="form-inline" type="get" action="{{url('/search_work')}}" role="search" method="get">
<input id="search-input" type="search" name="query" class="form-control" placeholder="Search...">
<button type="submit" class="btn btn-primary"><i class="fa fa-search" aria-hidden="true"></i></button>
</form>
<br/>
<p style="text-align:center">
<button onclick="window.location.href='/workview'" type="button" class="btn btn-outline-primary">View</button><small style="color:#3490dc"> {{$count = DB::table('jobs')->count()}}</small> <small>Posts</small>
</p>
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingThree">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
<i class="fa fa-product-hunt" aria-hidden="true"></i> Sell
</button>
</h5>
</div>
<div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordion">
<div class="card-body">
<form class="form-inline" type="get" action="{{url('/search_sell')}}" role="search" method="get">
<input id="search-input" type="search" name="query" class="form-control" placeholder="Search...">
<button type="submit" class="btn btn-primary"><i class="fa fa-search" aria-hidden="true"></i></button>
</form>
<br/>
<p style="text-align:center">
<button onclick="window.location.href='/sellview'" type="button" class="btn btn-outline-primary">View</button><small style="color:#3490dc"> {{$count = DB::table('announces')->count()}}</small> <small>Posts</small>
</p>
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingFour">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseFour" aria-expanded="false" aria-controls="collapseFour">
<i class="fa fa-product-hunt" aria-hidden="true"></i> Tenders
</button>
</h5>
</div>
<div id="collapseFour" class="collapse" aria-labelledby="headingFour" data-parent="#accordion">
<div class="card-body">
<form class="form-inline" type="get" action="{{url('/search_tender')}}" role="search" method="get">
<input id="search-input" type="search" name="query" class="form-control" placeholder="Search...">
<button type="submit" class="btn btn-primary"><i class="fa fa-search" aria-hidden="true"></i></button>
</form>
<br/>
<p style="text-align:center">
<button onclick="window.location.href='/tenderview'" type="button" class="btn btn-outline-primary">View</button><small style="color:#3490dc"> {{$count = DB::table('Kinds')->count()}} </small><small>Posts</small>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br/>
#include('footer')
#endsection
My controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\User;
use DB;
class PostController extends Controller
{
//
public function mapost()
{
$data = Auth::user()->Announce::orderBy('created_at', 'DESC')->get();
return view('users.mapost',['data'=>$data]);
}
}
My route in web.php
Route::get('users/mapost', 'PostController#mapost')->name('users.mapost');
I don`t know where I am getting this wrong, i will appreciate any help thanks in advance
Look at this line:
$data = Auth::user()->Announce::orderBy('created_at', 'DESC')->get();
Here you attempt to call the orderBy method of the Auth::user()->Announce class and of course, such class does not exist. It would make sense to do something like this:
Announce::where('user_id', $youruserid)->orderByDesc('created_at');
Tried all the possible solution to refresh the component but failed. Is there any option not to push the new comments and refresh the $comments variable whatever it contains?
Want to refresh $comments and its relation with replies in the blade on click of the send button
Calling $refresh action on the send button but it doesn't seem to work. Even tried to re-render the component with $this->render(). This also fails.
<div>
#foreach($comments as $item)
<div class="row" #if($item->reply_id != null) style="margin-left:40px;" #endif>
<div class="col-md-12">
<div class="py-md-4 py-3 border_bottom" >
<div class="row">
<div class="col-md-1 col-sm-1 col-1">
<div class="rating_person pt-3">
<img src="{{ isset($item->owner->profile_picture) ? asset($item->owner->profile_picture) : asset('images/default.jpg') }}">
</div>
</div>
<div class="col-md-11 col-sm-12 col-12">
<div class="rating_view_here_content_single_border">
<div class="rating_view_here_content_single">
<div class="rating_view_stars d-flex justify-content-between pt-3">
<div class="rating_view_heading">
<h4>{{ $item->owner->name }}</h4>
<div class="rating_wrapper">
<a href="#" class="grey_rating active-rating">
<i class="fa fa-star" aria-hidden="true"></i>
</a>
<a href="#" class="grey_rating active-rating">
<i class="fa fa-star" aria-hidden="true"></i>
</a>
<a href="#" class="grey_rating active-rating">
<i class="fa fa-star" aria-hidden="true"></i>
</a>
<a href="#" class="grey_rating active-rating">
<i class="fa fa-star" aria-hidden="true"></i>
</a>
<a href="#" class="grey_rating active-rating">
<i class="fa fa-star" aria-hidden="true"></i>
</a>
</div>
</div>
<span class="rating_days">{{ \App\Library\Helper::getTime($item->created_at) }}</span>
</div>
<div class="rating_comment_here pt-3">
<p>{{ $item->comment }}</p>
<p>
<a href="javascript:void(0)" class="reply" data-id="{{ $item->id }}" wire:click="toggleCommentBox({{ $item->id }}, 'true')">
<i class="fa fa-reply" aria-hidden="true"></i> <span>Reply</span>
</a>
</p>
</div>
#if($item_id == $item->id && $show=="true")
<div class="video_inner_form_wrapper commentBox-{{ $item->id }}">
<form wire:submit.prevent="sendReply" class="row">
<input type="hidden" name="reply_id" value="{{ $item->id }}">
<div class="comment_input col-md-8">
<input type="text" class="bluish_label video_inner_input #error('replyText') is-invalid #enderror" wire:model.lazy="replyText" placeholder="Write your comment here">
#error('replyText')
<div class="invalid-feedback">{{$message}}</div>
#enderror
</div>
<div class="col-md-4">
<button type="submit" class="btn_edit text-uppercase" wire:click="$refresh">Send</a>
<button type="button" class="btn_edit text-uppercase cancel" wire:click="toggleCommentBox({{ $item->id }}, 'false')">Cancel</a>
</div></form>
</div>
#endif
</div>
</div>
</div>
</div>
</div>
<livewire:frontend.discussion-chat :key="'chat-' . $item->id" :comments="$item->replies" :id="$model_id" :type="$model_type" />
</div>
</div>
#endforeach
</div>
Since none of the properties is updated, the livewire chat component will not refresh.
Possible solution is not to pass the list as a param but fetch it inside the chat component. Use events to trigger a refresh:
#click="$emit('discussion.chat.{{ $id }}.refresh')"
Inside frontend.discussion-chat have a
public function listeners(): array
{
return [
"discussion.chat.$this->id.refresh" => "reload"
];
}
public function reload(): void
{
// E.g.
$this->comments->fresh();
}
I wrote the following code to display some products on a page but all that I want is to display only 3 items in a row.
My code for displaying all products (i have to display more than 15 products):
<div class="products">
<div class="row">
#foreach($products as $item)
<div class="col-md-4 col-sm-6 col-xs-12 ">
<div class="blog-item item swin-transition">
<div class="block-img">
<img style="width: 269.844px;height: 254.984px " src="{{url('images/product/'.$item['image'])}}" alt="" class="img img-responsive">
<div class="group-btn">
<i class="icons fa fa-link"></i>
<i class="fa fa-shopping-basket"></i>
</div>
</div>
<div class="block-content">
<h6 class="title" style="font-size: 15px">
{{$item['name_'.$lang]}}
</h6>
<div class="product-info">
<ul class="list-inline">
<li class="author">
<span>{{Lang::get('frontend.price')}}:</span>
<span class="text">{{number_format($item['online_price'])}} {{Lang::get('frontend.unit')}}</span>
</li>
<li class="rating">
<a href="javascript:void(0)" tabindex="0">
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star-o"></i>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
#endforeach
</div>
</div>
php `array_chunk()` function will serve your purpose [http://php.net/manual/en/function.array-chunk.php][1]
<div class="products">
#foreach(array_chunk($products,3,true) as $chunk)
<div class="row">
#foreach($chunk as $item)
<div class="col-md-4 col-sm-6 col-xs-12 ">
<div class="blog-item item swin-transition">
<div class="block-img">
<img style="width: 269.844px;height: 254.984px " src="{{url('images/product/'.$item['image'])}}" alt="" class="img img-responsive">
<div class="group-btn">
<i class="icons fa fa-link"></i>
<i class="fa fa-shopping-basket"></i>
</div>
</div>
<div class="block-content">
<h6 class="title" style="font-size: 15px">{{$item['name_'.$lang]}}</h6>
<div class="product-info">
<ul class="list-inline">
<li class="author"><span>{{Lang::get('frontend.price')}}:</span><span class="text">{{number_format($item['online_price'])}} {{Lang::get('frontend.unit')}}</span></li>
<li class="rating"><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star-o"></i></li>
</ul>
</div>
</div>
</div>
</div>
#endforeach
</div>
#endforeach;
</div>
[1]: http://php.net/manual/en/function.array-chunk.php
i have a page "deposits" here are plans are availble with the use of "foreach"
now i wnt to show only plan number 3 here. mean plan of id 3.
<div class="row">
#foreach($plan as $p)
<div class="col-sm-4 text-center">
<div class="panel panel-info panel-pricing">
<div class="panel-heading">
<h3 style="font-size: 28px;"><b>{{ $p->name }}</b></h3>
</div>
<div style="font-size: 18px;padding: 18px;" class="panel-body text-center">
<p><strong>{{ $p->minimum }} {{ $basic->currency }} - {{ $p->maximum }} {{ $basic->currency }}</strong></p>
</div>
<ul style='font-size: 15px;' class="list-group text-center bold">
<li class="list-group-item"><i class="fa fa-check"></i> Commission - {{ $p->percent }} <i class="fa fa-percent"></i> </li>
<li class="list-group-item"><i class="fa fa-check"></i> Time - {{ $p->time }} times </li>
<li class="list-group-item"><i class="fa fa-check"></i> Compound - <span class="aaaa">{{ $p->compound->name }}</span></li>
</ul>
<div class="panel-footer" style="overflow: hidden">
<div class="col-sm-12">
<button type="button" class="btn btn-info btn-block btn-icon icon-left delete_button"
data-toggle="modal" data-target="#DelModal"
data-id="{{ $p->id }}">
<i class="fa fa-send"></i> Invest Under This Package
</button>
</div>
</div>
</div>
</div>
#endforeach
</div>
You can simply extract the plan from your $plan collection , does not need loop in below case
$p = $plan ->find(3);
if you want to use foreach and show plan id 3 , then try this :
<div class="row">
#foreach($plan as $p)
#if($p == 3)
<div class="col-sm-4 text-center">
<div class="panel panel-info panel-pricing">
<div class="panel-heading">
<h3 style="font-size: 28px;"><b>{{ $p->name }}</b></h3>
</div>
<div style="font-size: 18px;padding: 18px;" class="panel-body text-center">
<p><strong>{{ $p->minimum }} {{ $basic->currency }} - {{ $p->maximum }} {{ $basic->currency }}</strong></p>
</div>
<ul style='font-size: 15px;' class="list-group text-center bold">
<li class="list-group-item"><i class="fa fa-check"></i> Commission - {{ $p->percent }} <i class="fa fa-percent"></i> </li>
<li class="list-group-item"><i class="fa fa-check"></i> Time - {{ $p->time }} times </li>
<li class="list-group-item"><i class="fa fa-check"></i> Compound - <span class="aaaa">{{ $p->compound->name }}</span></li>
</ul>
<div class="panel-footer" style="overflow: hidden">
<div class="col-sm-12">
<button type="button" class="btn btn-info btn-block btn-icon icon-left delete_button"
data-toggle="modal" data-target="#DelModal"
data-id="{{ $p->id }}">
<i class="fa fa-send"></i> Invest Under This Package
</button>
</div>
</div>
</div>
</div>
#endif
#endforeach
</div>
But i suggest not to use foreach as you already know you need to show only plan id 3 . Try this :
<div class="row">
<?php $p = $plan["your_desired_id"]; ?> // means 2 or 3 .. whatever your desired id
<div class="col-sm-4 text-center">
<div class="panel panel-info panel-pricing">
<div class="panel-heading">
<h3 style="font-size: 28px;"><b>{{ $p->name }}</b></h3>
</div>
<div style="font-size: 18px;padding: 18px;" class="panel-body text-center">
<p><strong>{{ $p->minimum }} {{ $basic->currency }} - {{ $p->maximum }} {{ $basic->currency }}</strong></p>
</div>
<ul style='font-size: 15px;' class="list-group text-center bold">
<li class="list-group-item"><i class="fa fa-check"></i> Commission - {{ $p->percent }} <i class="fa fa-percent"></i> </li>
<li class="list-group-item"><i class="fa fa-check"></i> Time - {{ $p->time }} times </li>
<li class="list-group-item"><i class="fa fa-check"></i> Compound - <span class="aaaa">{{ $p->compound->name }}</span></li>
</ul>
<div class="panel-footer" style="overflow: hidden">
<div class="col-sm-12">
<button type="button" class="btn btn-info btn-block btn-icon icon-left delete_button"
data-toggle="modal" data-target="#DelModal"
data-id="{{ $p->id }}">
<i class="fa fa-send"></i> Invest Under This Package
</button>
</div>
</div>
</div>
</div>
</div>
If you need to find out a single value of plan from the collection .
You can just find it by it's plan id
$plan = Plan::find(3);
Write this in your controller and then pass it down to your view blade file by using with.
Example :
return view("blade file name")->with(['plan'=>$plan])
Later in your blade file just access it's fields.
{{$plan->field_name}}
I want to shorten a string when it's longer than a certain length for example 20.
But when I add the if statement to my echoed html it outputs the result outside of the echoed html. Any idea why this happens?
My code:
foreach($contentcr as $content)
{
$contentje .= '<li class="job_listing">
<a href="http://www.website.nl/_extern/website/content.php?alias='.$content['alias'].'">
<div class="location job_img">
<img src="images/samples/person1.jpg" alt="" class="company_logo">
</div>
<div class="location boldfont">
'.$content['title'].'
</div>
<div class="location">
'.$content['fulltext'].'';
if (strlen($content['fulltext']) >= 20){
echo 'blala';
}
$contentje .='</div>
<div class="rating location">
<div class="rating-stars">
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
</div>
</div>
<div class="location">
'.$content['metakey'].'
</div>
<div class="location">
<button type="submit" class="btn btn-primary buttonblock" onClick="location.href="http://www.website.nl/_extern/website/content.php?page="'.$content['alias'].'">Nu huren</button>
</div>
</a>
</li>'; // Here
}
This is a table like structure, but the output of the if statement is echoed outside the html markup.
You are echoing the string inside if statement rather than appending that to your $contentje variable. See if statement below:
foreach($contentcr as $content)
{
$contentje .= '<li class="job_listing">
<a href="http://www.website.nl/_extern/website/content.php?alias='.$content['alias'].'">
<div class="location job_img">
<img src="images/samples/person1.jpg" alt="" class="company_logo">
</div>
<div class="location boldfont">
'.$content['title'].'
</div>
<div class="location">
'.$content['fulltext'].'';
if (strlen($content['fulltext']) >= 20){
$contentje .= 'blala';
}
$contentje .='</div>
<div class="rating location">
<div class="rating-stars">
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
</div>
</div>
<div class="location"> '.$content['metakey'].'</div>
<div class="location">
<button type="submit" class="btn btn-primary buttonblock" onClick="location.href="http://www.website.nl/_extern/website/content.php?page="'.$content['alias'].'">Nu huren</button>
</div>
</a></li>'; // Here
}