I've created extremely simple module for Opencart, just displaying hello world in the admin panel. Here is my controller:
<?php
class ControllerExtensionModuleHelloworld extends Controller {
public function index(){
$this->load->language('/extension/module/helloworld');
$this->document->setTitle('Hello World');
$data['heading_title'] = $this->language->get('heading_title');
$data['helloworld'] = $this->language->get('helloworld');
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('extension/module/helloworld', $data));
}
}
Here is my view:
{{header}}
<div class="container">
<div class="row>
<div class="col">
{{column_left}}
</div>
<div class="col">
<h1>{{heading_title}}</h1>
<p>{{helloworld}}</p>
</div>
</div>
</div>
{{footer}}
The problem is that the h1 and the p tags are displayed under the the column-left like this:
I changed the col classes with col-sm-4 and col-sm-8 like this:
{{header}}
<div class="container">
<div class="row>
<div class="col-sm-3">
{{column_left}}
</div>
<div class="col-sm-8">
<h1>{{heading_title}}</h1>
<p>{{helloworld}}</p>
</div>
</div>
</div>
{{footer}}
But this didn't work, finally I added col-sm-offset-2 class to the col-sm-8 div, and it shifted the text left, like it's suppose to be.
Any ideas where the problem may be?
{{ header }} {{column_left}}
<div id="content">
<div class="page-header">
<div class="container-fluid">
<h1>{{ heading_title }}</h1>
</div>
</div>
<div class="container-fluid">
<!-- content here -->
</div>
</div>
{{ footer }}
Try this, it should work.
Related
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
here is the function is given below
public function index(){
$student=Administration::Where('payment',1)->get();
//dd($student);
return view('HallAuthority.index',compact('student'));
}
Here is the view blade
<div class="container-fluid page-body-wrapper">
<div class="row row-offcanvas row-offcanvas-right">
<!-- partial:partials/_sidebar.html -->
#include('HallAuthority.inc.sidebar')
<!-- partial -->
<div class="content-wrapper">
<div class="row">
<div class="col-sm-6 col-md-3 grid-margin">
<div class="card">
<div class="card-body">
{{$student->count()}}
<h2 class="card-title">Total sutdent Student</h2>
</div>
<div class="dashboard-chart-card-container">
<div id="dashboard-card-chart-1" class="card-float-chart"></div>
</div>
</div>
</div>
<div class="col-sm-6 col-md-3 grid-margin">
<div class="card">
<div class="card-body">
<h2 class="card-title">Total Department</h2>
</div>
<div class="dashboard-chart-card-container">
<div id="dashboard-card-chart-2" class="card-float-chart"></div>
</div>
</div>
</div>
<div class="col-sm-6 col-md-3 grid-margin">
<div class="card">
<div class="card-body">
<h2 class="card-title">stock price Price</h2>
</div>
<div class="dashboard-chart-card-container">
<div id="dashboard-card-chart-3" class="card-float-chart"></div>
</div>
</div>
</div>
<div class="col-sm-6 col-md-3 grid-margin">
<div class="card">
<div class="card-body">
<h2 class="card-title">Revenue</h2>
</div>
<div class="dashboard-chart-card-container">
<div id="dashboard-card-chart-4" class="card-float-chart"></div>
</div>
</div>
</div>
</div>
</div>
<!-- content-wrapper ends -->
<!-- partial:partials/_footer.html -->
<div class="card card-body">
<div class="card-header text-center">
Mahfujur#2019
</div>
</div>
<!-- partial -->
</div>
<!-- row-offcanvas ends -->
</div>
The Route file is given below
Route::get('/student/hall','HallController#index')->name('student.hall');
Given this type an error
Undefined variable: student (View: C:\xampp\htdocs\ProjectFinall\resources\views\HallAuthority\index.blade.php) (View: C:\xampp\htdocs\ProjectFinall\resources\views\HallAuthority\index.blade.php)*
I get the value properly but i cannot compact this value to the view pages its always shows that it is undefined value i am totally fed up to solve this . Please anyone help me.
Try this
public function index(){
$student=Administration::Where('payment',1)->count();
return view('HallAuthority.index',compact('student'));
}
<div class="card-body">
{{$student}}
<h2 class="card-title">Total sutdent Student</h2>
</div>
I am newbie for laravel and doing my first project called blog. For post article i can fetch data but I am trying to display reader's comment in the index page just below the article by fetching from database but it gives error(For info,I have already inserted a row from xammp just to fetch).Here is the code for PostController.php
public function index()
{
//$show = Post::all();
$show = Post::orderBy('id','desc')->paginate(1);
return view('pages/blog')->with('post',$show);
}
public function comment()
{
$show = readerComment::all();
return view('pages/blog')->with('commentShow',$show);
}
In index pages or blog.blade.php
#if(count($post)>0)
#foreach($post as $article)
<div class = "row">
<div class="col-md-12">
<h3 class="text-center">{{$article->title}}</h2>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p>{!!$article->article!!}</p>
</div>
</div>
<!-- Comment section -->
<div class = "comment">
<h3>Comments</h3>
#foreach($commentShow as $commShow)
<div class = "row">
<div class = "col-md-12">
<p>{{$commShow->comment}}</p>
<p>{{$commShow->name}}</p>
</div>
</div>
#endforeach
</div>
And in web route
Route::resource('posts','PostController');
Route::get('/','PostController#comment');
I get error as
Undefined variable: post (View: C:\xampp\htdocs\blogging\resources\views\pages\blog.blade.php)
Any help would be appreciated. Thanks
Do it like that,
public function index()
{
$posts = Post::orderBy('id','desc')->paginate(1);
return view('pages.blog',compact('posts'));
}
You're blade looks good without error, but let's try this view..
#extends('layouts.app')
#section('content')
#if(count($post)>0)
#foreach($post as $article)
<div class = "row">
<div class="col-md-12">
<h3 class="text-center">{{$article->title}}</h2>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p>{!!$article->article!!}</p>
</div>
</div>
<!-- Comment section -->
<div class = "comment">
<h3>Comments</h3>
#foreach($post as $commShow)
<div class = "row">
<div class = "col-md-12">
<p>{{$commShow->comment}}</p>
<p>{{$commShow->name}}</p>
</div>
</div>
#endforeach
</div>#endsection
Here you are defining your Eloquent Collection of models to be $commentShow:
return view('pages/blog')->with('commentShow',$show);
In your view, you are using the variable $post.
You need to change one of them to match the other.
in addition to this:
When you use the ->with() method the first parameter passed to it is
the name of the variable available on the view. So for the comment
part you make this call ->with('commentShow',$show); yet in your view
you try and access it via $post. Change this line #foreach($post as
$commShow) to #foreach($commentShow as $commShow)
change you view code to this: (please note the changed variable name in second #foreach)
#if(isset($post) && !empty($post))
#foreach($post as $article)
<div class="row">
<div class="col-md-12">
<h3 class="text-center">{{$article->title}}</h2>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p>{!!$article->article!!}</p>
</div>
</div>
#endforeach
#endif
#if(isset($commentShow) && !empty($commentShow))
<!-- Comment section -->
<div class="comment">
<h3>Comments</h3>
#foreach($commentShow as $commShow)
<div class="row">
<div class="col-md-12">
<p>{{$commShow->comment}}</p>
<p>{{$commShow->name}}</p>
</div>
</div>
#endforeach
</div>
#endif
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);
}
I have a model class
<?php
class CategoriaModificador extends Base
{
protected $table = 'categorias_modificadores';
public function restaurantes()
{
return $this->hasMany('CategoriaModificadorRestaurante', 'categorias_modificadores_id');
}
}
When I try to pass the variable to the blade view in my controller
public function show($id = 0)
{
if (!get_session_empresa()) {
return Redirect::route('empresa.logar')->with('message_error', 'Você precisa está logado');
}
$categoriaModificador = CategoriaModificador::where('empresas_id', (int)get_session_empresa()->id)
->where("id", (int)$id)
->first();
return View::make('frontend.' . $this->theme_base . '.categoria-modificador.show')
->with('categoriaModificador', $categoriaModificador);
}
I find this error
This is my show.blade.html
#extends('frontend.default.base_restrita')
#section('title')
Categoria de Modificador - {{ config_value('site_nome') }}
#stop
#section('content')
<section id="main-content">
<section class="wrapper">
<section class="panel">
<header class="panel-heading">
{{$categoriaModificador->nome}}
</header>
<div class="panel-body">
<div class="clearfix">
<div class="row">
<div class="col-lg-5">
<h4 class="pull-right"> Nome:</h4>
</div>
<div class="col-lg-6">
<h4 class="pull-left"> {{$categoriaModificador->nome}}</h4>
</div>
</div>
<div class="row">
<div class="col-lg-5">
<h4 class="pull-right"> Obrigatório:</h4>
</div>
<div class="col-lg-6">
<h4 class="pull-left"> {{$categoriaModificador->obrigatorio}}</h4>
</div>
</div>
<div class="row">
<div class="col-lg-5">
<h4 class="pull-right"> Máximo de Opções:</h4>
</div>
<div class="col-lg-6">
<h4 class="pull-left"> {{$categoriaModificador->maximo_opcoes}}</h4>
</div>
</div>
<div class="row">
<div class="col-lg-5">
<h4 class="pull-right"> Restaurantes:</h4>
</div>
#for($i=0;$i<$categoriaModificador->restaurantes->count();$i++)
#if($i==0)
<div class="col-lg-6">
<h4 class="pull-left">{{$$categoriaModificador->restaurantes[$i]->nome}}</h4><br>
</div>
#else
<div class="col-lg-5">
<h4 class="pull-right"></h4>
</div>
<div class="col-lg-6">
<h4 class="pull-left">{{$$categoriaModificador->restaurantes[$i]->nome}}</h4><br>
</div>
#endif
#endfor
</div>
</div>
</div>
</section>
</section>
</section>
#stop
Thanks for posting the view. I think the problem is you're using $categoriaModificador->restaurantes[$i]->nome, but it seems you do not have nome in your $categoriaModificador->restaurantes collection.
Also, why are you using double dollar sign with $$categoriaModificador?
If you clearly look at your error, you will find your solution yourself. Undefined variable error means you are printing something in the view file that is not defined.
For general solution, you should check if the variable is defined previously or is passed to the view. This may helps other.
Thanks