Question like this are asked, i have searched a lot but found nothing which works for me.
Here is Controller function:
public function showHomePage() {
$communities = Community::all();
$ideas = Idea::paginate(8);
return view('publicPages.index', compact(['communities', 'ideas']));
}
Now the paginate method is working but when in view i call the method stated in documentation Docs
{!! $idea->render() !!}
It generates following error
Call to undefined method Illuminate\Database\Query\Builder::render()
I have also tried {!! $idea->render() !!} but the issue is same. Tried this also $ideas = DB::table('ideas')->paginate(8);
Here is view :
#foreach($ideas as $idea)
<div class="lst-popular-project clearfix">
<div class="grid_3">
<div class="project-short sml-thumb">
<div class="top-project-info">
<div class="content-info-short clearfix">
<a href="{{URL::to('showidea', array($idea->id))}}" class="thumb-img">
<img src="{{asset($idea->idea_image)}}" alt="$TITLE">
</a>
<div class="wrap-short-detail">
<h3 class="rs acticle-title">
<a class="be-fc-orange" href="project">
{{$idea->idea_title}}
</a>
</h3>
<p class="rs tiny-desc">
by
<a href="profile.html" class="fw-b fc-gray be-fc-orange">
{{$idea->User->name}}
</a>
</p>
<p class="rs title-description">
{{$idea->idea_info}}
</p>
<p class="rs project-location">
<i class="icon iLocation"></i>
{{$idea->idea_location}}
</p>
</div>
</div>
</div>
</div>
</div>
#endforeach
you must replace
{!! $idea->render() !!}
with
{!! $ideas->render() !!}
$ideas variable contains from,total,page etc
I guess it shoule be $ideas:
{!! $ideas->render() !!}
Related
Hello for everyone I have a problem in laravel that about the showing images in one view, the problem is: I have a page that just show the images but it show all the images stored in table with specific id but I want to show some of that and have a button (show more) and when click on button it show the other images I don't know hove can I do this if someone can help me please!
This is my controller code:
public function listHostel()
{
$hostels = Hostel::all();
return view('front/khabgah_list',compact('hostels'));
}
And this is my blade code:
#foreach($hostels as $hostel)
#foreach($hostel->attachments as $photo)
<div class=" col-12 col-sm-6 col-md-6 col-lg-3 px-1 mt-3">
<div class="card card-shadow custom-height-1 " style="border-radius: 0%">
<a href="">
<img src="/assets-/app/media/img/blog/hostels-img/{{$photo->file_name}}"
class="card-img-top card-img custom-card-img-height" alt="">
</a>
<div class="car-body">
<div class="card-footer">
<div class="custom-circle">
<p class="custom-circle-text card-text">
<b>
#if($hostel->type == 1)
{{ 'ذکور'}}
#else
{{ 'اناث' }}
#endif
</b>
</p>
</div>
<div class="custom-prices card-text text-left"> کرایه فی ماه
: {{$hostel->remark }}
</div>
</div>
</div>
</div>
</div>
#endforeach
#endforeach
Pagination is likely what you're looking for. Change your controller to:
public function listHostel()
{
$hostels = Hostel::all()->paginate(5);
return view('front/khabgah_list',compact('hostels'));
}
Then you can get the links in your Blade template:
{{ $hostels->links() }}
You might need to change it a bit to work for your specific situation. The documentation gives some more info: https://laravel.com/docs/5.8/pagination
I want to display the order details form database. I store cart data into database using serialize method. When i want to display data i can not properly show it. only can print order object. And there give that a error.That is
(1/1) FatalErrorException syntax error, unexpected 'endforeach'
(T_ENDFOREACH) in 9ad30ab1db6ca668d8a75c428e65858dc800d045.php line 27
.
<div class="row">
<div class="col-md-8 col-md-offset-2">
<h1>User Profile</h1>
<hr>
<h2>My Oders</h2>
#foreach($orders as $order)
<div class="panel panel-default">
<div class="panel-body">
<ul class="list-group">
#forecah($order->cart->items as $product)
<li class="list-group-item">
<span class="badge">{{$product['product_price']}}
</span>
{{$product['item']['product_name']}} |
{{$product['qty']}} Units
</li>
#endforeach
</ul>
</div>
<div class="panel-footer">
<strong>Total Price : {{$order->cart->totalPrice}}</strong>
</div>
</div>
#endforeach
</div>
</div>
You have typo in your code:
#forecah($order->cart->items as $product)
Try to change into:
#foreach($order->cart->items as $product)e
Hope it works..as it does not detect the foreach loop before.
You have wrong spelling of forecah. you should correct the spelling.
Look at the second foreach and change the spelling.
You can copy code below as i have changed the spelling.
<div class="row">
<div class="col-md-8 col-md-offset-2">
<h1>User Profile</h1>
<hr>
<h2>My Oders</h2>
#foreach($orders as $order)
<div class="panel panel-default">
<div class="panel-body">
<ul class="list-group">
#foreach($order->cart->items as $product)
<li class="list-group-item">
<span class="badge">{{$product['product_price']}}
</span>
{{$product['item']['product_name']}} |
{{$product['qty']}} Units
</li>
#endforeach
</ul>
</div>
<div class="panel-footer">
<strong>Total Price : {{$order->cart->totalPrice}}</strong>
</div>
</div>
#endforeach
</div>
I'm new to Laravel and using ver 5.5. I have a simple view and when I run the code, instead of showing the rendered version, I see the Blade commands.
This is the view code:
#section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>{{ $title }}</h2>
</div>
<div class="pull-left">
{!! \App\Combine\BaseCombine::tableHeader($collection) !!}
{!! \App\Combine\BaseCombine::tableData($collection) !!}
{!! \App\Combine\BaseCombine::tableFooter($collection) !!}
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('transaction.index') }}"> Back</a>
</div>
</div>
</div>
#endsection
Here is the code in the controller that executes the view:
return view('general.genericTable',
[
'title' => __FUNCTION__,
'transactionID' => $transactionsID,
'type' => $type,
'collection' => TransactionCombine::agents($transactionsID, $type),
]
);
This is what I see when I execute the code:
#section('content')
{{ $title }}
{!! \App\Combine\BaseCombine::tableHeader($collection) !!} {!! \App\Combine\BaseCombine::tableData($collection) !!} {!! \App\Combine\BaseCombine::tableFooter($collection) !!}
Back
#endsection
What have I done wrong?
I need allow links in messages, when user send message. How I can do this?
#foreach($mess as $message)
<li data-mid="{{ $message->id }}">
<div class="row margin-left-none margin-right-none">
<div class="col-md-2 padding-right-none">
<div class="avatar-user text-center">
<img src="{{ $message->sender->avatar }}" alt="$message->sender->name">
</div>
</div>
<div class="col-md-10 padding-left-none">
<div class="user-name">
<span>{{ $message->sender->name }}
#if(Helper::getOnlineUser($message->sender->id))
<i data-toggle="tooltip" title="Онлайн" class="material-icons online">fiber_manual_record</i>
#else
<i data-toggle="tooltip" title="Оффлайн" class="material-icons offline">fiber_manual_record</i>
#endif
<span class="date float-right">{{ $message->created_at->formatLocalized('%H:%m') }}</span></span>
</div>
<div class="message">
{{ $message->body }}
</div>
</div>
</div>
</li>
#endforeach
This is view of messages.
How I can allow links?
Example: http://example.com in messages =>
http://example.com
I need {!! $message->body !!} ? Or How?
In controller:
$mess = Chat::conversations($conversation)->for($user)->getMessages($limit, $request->page);
I use this package: https://github.com/musonza/chat
There are built in PHP functions to handle this:
<div class="message">
{!! strip_tags($message->body, '<a>') !!}
</div>
Where the second argument is your whitelist.
This has the following advantages:
You're not messing with regex
You're still using blade {!!!!}
You're using well tested code dev'ed by the core team
You can do it by using following php function in your blade,
<?php
function getDataWithURL($text){
// The Regular Expression filter
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
// Check if there is a url in the text
if(preg_match($reg_exUrl, $text, $url)) {
// make the urls hyper links
echo preg_replace($reg_exUrl, "".$url[0]." ", $text);
} else {
// if no urls in the text just return the text
echo $text;
}
}
?>
You just need to add this code in your blade file and then you can check and replace the links in your text like this,
<div class="message">
<?php getDataWithURL($message->body);?>
</div>
I hope you will understand.
I am using voyager backoffice with laravel, and i'm having a problem with the blade coming from the database, all the code works except the blade, all the blade code outside the database works well.
I've already used {{ }}, {!! !!}, {{{ }}}, Html_entity_decode () but nothing works.
Any help is appreciated.
Thank you
View:
#extends ('layout')
#section ('content')
#foreach ($pageContent as $page)
{!! $page->slug !!}
{!! $page->title !!}
{!! $page->body !!}
#endforeach
#endsection
body that came from db:
<div class="container contacts_content_container">
<div class="row">
<div class="col-sm-12 text-center">
<div class="content">
<h1>Contact US Form</h1>
#if(Session::has('success'))
<div class="alert alert-success">
{{ Session::get('success') }}
</div>
#endif
{!! Form::open(['route'=>'contactus.store']) !!}
<div class="form-group {{ $errors->has('name') ? 'has-error' : '' }}">
{!! Form::label('Name:') !!}
{!! Form::text('name', old('name'), ['class'=>'form-control', 'placeholder'=>'Enter Name']) !!}
<span class="text-danger">{{ $errors->first('name') }}</span>
</div>
<div class="form-group {{ $errors->has('email') ? 'has-error' : '' }}">
{!! Form::label('Email:') !!}
{!! Form::text('email', old('email'), ['class'=>'form-control', 'placeholder'=>'Enter Email']) !!}
<span class="text-danger">{{ $errors->first('email') }}</span>
</div>
<div class="form-group {{ $errors->has('message') ? 'has-error' : '' }}">
{!! Form::label('Message:') !!}
{!! Form::textarea('message', old('message'), ['class'=>'form-control', 'placeholder'=>'Enter Message']) !!}
<span class="text-danger">{{ $errors->first('message') }}</span>
</div>
<div class="form-group">
<button class="btn btn-success">Contact US!</button>
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
Controller:
<?php
namespace App\Http\Controllers;
use App\Page;
use Illuminate\Routing\Controller;
class PageController extends Controller {
/**
* Display a listing of the resource.
*
* #return Response
*/
public function index()
{
// get all the pages
$pages = Page::all();
// load the view and pass the pages
return view('public.about')
->with('pages', $pages);
}
public function slug($slug)
{
// get page where slug
$pageContent = Page::where('slug', $slug)->get();
// load the view and pass the page content
return view('public.' . $slug)
->with('pageContent', $pageContent);
}
}
Routes:
//Pages Routing With slug
Route::get('/{slug}','PageController#slug');
I'd say keeping templates in a DB is not a good idea, but if you really need it you can parse Blade template manually. There are multiple ways to do that and one of these is using compileString() method:
$html = Blade::compileString($page->template);
May be compileString() might help you.Try this
Blade::compileString('Your blade syntax from db {!! $variable !!}');