How to divide a file into multiple files with laravel or php?
For example:
There is a file demo.blade.php:
<div class="card-block">
<div class="row">
<div class="col-1">fruits</div>
<div class="col-11">
apple,pear,peach
</div>
</div>
</div>
<div class="card-block">
<div class="row">
<div class="col-1">aminals</div>
<div class="col-11">
cat,dog,calf
</div>
</div>
</div>
<div class="card-block">
<div class="row">
<div class="col-1">vehicles</div>
<div class="col-11">
car,bus,motorbike
</div>
</div>
</div>
I want to write some code to divide the demo.blade.php into three files:
fruits.blade.php
aminals.blade.php
vehicles.blade.php
The content is each <div class="card-block"></div>.
How to do it?
Any help would be appreciated.
You can use other blade in your blade file like this :
#include('fruits.blade.php')
#include('aminals.blade.php')
#include('vehicles.blade.php')
But this is not a good idea. Instead you can make a template like this :
<div class="card-block">
<div class="row">
<div class="col-1">{{ $title }}</div>
<div class="col-11">
{{ $content }}
</div>
</div>
</div>
And use it everywhere :
#include('template', ['title' => 'foo', 'content' => 'bar'])
Anyway I don't know your purpose of doing this. And you can explain more to give you more examples.
You can also use Blade Components
//This is the template cardblock.blade.php
<div class="card-block">
<div class="row">
<div class="col-1">{{ $title }}</div>
<div class="col-11">
{{ $slot }}
</div>
</div>
</div>
And you can use it like this
#component('cardblock')
#slot('title')
fruits
#endslot
apple,pear,peach
#endcomponent
#component('cardblock')
#slot('title')
aminals
#endslot
cat,dog,calf
#endcomponent
#component('cardblock')
#slot('title')
vehicles
#endslot
car,bus,motorbike
#endcomponent
Related
i would have the class "opacity" inserted only at the first "carousel-cell".
For the rest in the loop, they should not be there.
<div class="main-carousel">
#foreach($projects as $p)
#if($p->getMedia('teaser')->first() ?? "")
<div class="carousel-cell">
<div class="row">
<div id="project-info" class="col-lg-3 text-md-right pr-md-5 project-info">
<div class="project opacity">
<h2 class="project-title mb-0">{{$p->name}}</h2>
<h3 class="project-category">Foto / Video Produktion</h3>
</div>
</div>
<div class="col-lg-9 project-img opacity">
<a href="{{url('projects')}}/{{$p->slug}}">
<div class="start-teaser">
<img src="{{asset('storage')}}/{{$p->getMedia('teaser')->first()->id}}/{{$p->getMedia('teaser')->first()->file_name}}" alt="Land Rover">
</div>
</a>
</div>
</div>
</div>
#endif
#endforeach
</div>
You could use the $loop->first variable to add a class only on the first iteration of the loop.
Like this: <div class="carousel-cell {{ $loop->first ? 'opacity' : '' }}">
See more here:
https://laravel.com/docs/9.x/blade#the-loop-variable
I'm so confused, I was trying to fetch data from my database using laravel 8 and I'm sure I defined the variable right but it's having errors.
this is my controller:
public function homepage(){
$product_display = DB::table('products')->get();
return view('customer.homepage', compact('product_display'));
}
And this is the blade file:
<div class="content-wrapper pt-4">
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-lg-3">
<div class="card border border-danger">
<div class="card-body">
</div>
</div>
</div>
<div class="col-lg-9">
<div class="card border border-danger">
<div class="card-body">
#foreach($product_display as $pd)
<div class="card">
<h3>{{ $pd->prod_name }}</h3>
</div>
#endforeach
</div>
</div>
</div>
</div>
</div>
</section>
</div>
it says, product_display is not defined.
Use #dd($pd) in Blade foreach loop. You will see if the variable defined or not.
DB::get() returns a stdClass so maybe tryto use view('customer.homepage')->with(['product_display' => $product_display]) instead
im newbie about statamic,
im try to solve this code :
<div class="container">
<div class="intro">
<div class="row">
<div class="col-md-12">
<h2 class="title-uppercase text-white">{{ section_three_title }}</h2>
<div class="row-project-box row">
{{ relate:section_three_categories }}
{{ entries }}
<div class="col-project-box col-sm-6 col-md-4 col-lg-3">
<a href="{{ url }}" class="project-box">
<div class="project-box-inner">
<h5>{{ title }}</h5>
</div>
</a>
</div>
{{ /entries }}
{{ /relate:section_three_categories }}
</div>
view all projects <i class="icon icon-chevron-right"></i>
</div>
</div>
</div>
</div>
the code provide this :
i want to align these box
direzionale operativo dirigenziale not in horizonatal but in vertical like this:
direzionale
operativo
dirigenziale
i think that is a bootstrap configuration but i dont know about the statamic world
anyone can help me ?
thanks a lot
The problem here seems that you are using responsive breakpoints on your columns,
so if you want to set the boxes one below the other all the times you have to set the .col-project-box always be full-width adding this class col-12 and set the .row-project-box horizontal alignment center adding this class justify-content-center to it.
<div class="container">
<div class="intro">
<div class="row">
<div class="col-md-12">
<h2 class="title-uppercase text-white">{{ section_three_title }}</h2>
<div class="row-project-box row justify-content-center">
{{ relate:section_three_categories }}
{{ entries }}
<div class="col-project-box col-12">
<a href="{{ url }}" class="project-box">
<div class="project-box-inner">
<h5>{{ title }}</h5>
</div>
</a>
</div>
{{ /entries }}
{{ /relate:section_three_categories }}
</div>
view all projects <i class="icon icon-chevron-right"></i>
</div>
</div>
</div>
I have Laravel form with many multiple select elements which has many data. for ex:
Hotel select (600 option)
Restaurants select (800 option)
SPA select (200 option)
Attractions select (150 option)
Outlets select (500 option)
If I select all options in all inputs, in the controller when checking the
request the (Outlets) item has only 200 option
how to fix this? how to got all data sent from this form?
is there any form data size in Laravel?
This my form code:
<div class="row">
<div class="panel panel-white">
<div class="panel-body">
<div class="col-md-12 col-sm-12">
<div class="form-group">
{{ Form::label('hotels', __('membership::main.hotels')) }}
{{ Form::select('hotels', $hotels, null, array('multiple'=>'multiple','name'=>'hotels[]', 'class' => 'multiselect form-control')) }}
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-white">
<div class="panel-body">
<div class="col-md-12 col-sm-12">
<div class="form-group">
{{ Form::label('outlets', __('membership::main.outlets')) }}
{{ Form::select('outlets', $outlets, null, array('multiple'=>'multiple','name'=>'outlets[]', 'class' => 'multiselect form-control')) }}
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-white">
<div class="panel-body">
<div class="col-md-12 col-sm-12">
<div class="form-group">
{{ Form::label('airports', 'Airport & Lounges') }}
{{ Form::select('airports', $airports, null, array('multiple'=>'multiple','name'=>'airports[]', 'class' => 'multiselect form-control')) }}
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-white">
<div class="panel-body">
<div class="col-md-12 col-sm-12">
<div class="form-group">
{{ Form::label('beauty', 'Beauty & Fitness') }}
{{ Form::select('beauty', $beauty, null, array('multiple'=>'multiple','name'=>'beauty[]', 'class' => 'multiselect2 form-control')) }}
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-white">
<div class="panel-body">
<div class="col-md-12 col-sm-12">
<div class="form-group">
{{ Form::label('attractions', 'Activities & Attractions') }}
{{ Form::select('attractions', $attractions, null, array('multiple'=>'multiple','name'=>'attractions[]', 'class' => 'multiselect2 form-control')) }}
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-white">
<div class="panel-body">
<div class="col-md-12 col-sm-12">
<div class="form-group">
{{ Form::label('restaurants', 'Restaurant & Bars') }}
{{ Form::select('restaurants', $restaurants, null, array('multiple'=>'multiple','name'=>'restaurants[]', 'class' => 'multiselect3 form-control')) }}
</div>
</div>
</div>
</div>
</div>
And I am using this library to handle multiselect function
https://github.com/davidstutz/bootstrap-multiselect
in controller I just checking the data like this, and I not all my selection was submitted, its stop on specific limit but I don't know why?
public function store(Request $request)
{
dd($request);
}
Having so much options is not Ideal! However, I propose you look at your controller. Its possible that you paginate your result. Also it could be browser related. Until we see what you have done or what you seeing, we cannot give your an exact answer...only assumptions
I am making a forum and when the user clicks on a theme, a page shows up with every topic that belongs to that theme. The problem is, how do I do this?
I made a for each loop which shows ALL the topics from the database instead of the topics that belong to that theme I clicked on. How can I do this?
Web.php
Route::get('/', 'ThemesController#index')->name('home');
Route::get('/theme/{id}', 'ThemesController#show')->name('showtheme');
ThemesController.php
I only show the show method because I believe that's the only one necessary here
public function show($id)
{
$topics = Topic::all($);
return view('themes/topics')->with('topics', $topics);
}
topics.blade.php
#extends('layouts.default')
#section('content')
<div class="container main-content">
<div class="row first-row">
<div class="col s12">
<div class="card">
<div class="card-content clearfix">Nieuw topic</div>
</div>
</div>
<div class="col s12">
<div class="card">
<div class="card-content"><span class="card-title"> - Topics</span>
<div class="collection">
#foreach($topics as $topic)
<a href="" class="collection-item avatar collection-link"><img src="/uploads/avatars/{{ $topic->user->avatar }}" alt="" class="circle">
<div class="row">
<div class="col s6">
<div class="row last-row">
<div class="col s12"><span class="title">Theme - {{ $topic->topic_title }}</span>
<p>{!! str_limit($topic->topic_text, $limit = 100, $end = '...') !!}</p>
</div>
</div>
<div class="row last-row">
<div class="col s12 post-timestamp">Gepost door: {{ $topic->user->username }} op: {{ $topic->created_at }}</div>
</div>
</div>
<div class="col s2">
<h6 class="title center-align">Replies</h6>
<p class="center replies">{{ $topic->replies->count() }}</p>
</div>
<div class="col s2">
<h6 class="title center-align">Status</h6>
<div class="status-wrapper center-align"><span class="status-badge status-open">open</span></div>
</div>
<div class="col s2">
<h6 class="title center-align">Laatste reply</h6>
<p class="center-align">Naam</p>
<p class="center-align">Tijd</p>
</div>
</div>
</a>
#endforeach
</div>
</div>
</div>
</div>
<div class="col s12">
<div class="card">
<div class="card-content clearfix">Nieuw topic</div>
</div>
</div>
</div>
</div>
#endsection
I believe I'm doing something obviously wrong but I can't see what.
Help will be appreciated. Thanks in advance
If I miss some code, Please inform me.
How are you defining the relationship between a theme and it's topics? You'll have to have something like a one to many or many to many established in your database for you to be able to query correctly. Do you have anything like that yet?
****edit****
public function show($id)
{
$topics = Theme::find($id)->topics;
return view('themes/topics')->with('topics', $topics);
}