I just started learning Laravel, and I want to include a second controller into my main layout.
The route is the default root directory: /
And the layout looks like this:
<div class="container">
#yield('content')
</div>
<div class="basket">
~basket comes here~
</div>
I want to show the user's basket, but I need DB queries for that, and I can't find a way to include an other controller, atleast not with routing.
I'm not really asking for code (Sadly i didn't find a better place for this question), probably I just need a designing tip, I really feel I'm trying to do it wrong, since I couldn't find any relevant/helpful information for this.
And I dont want to put the basket into every controller that uses my main layout.
Any kind of help would be apreciated, I'm really lost :)
You should use view composers. Open you AppServiceProvider and inside the boot() method add the following:
view()->composer('your.layout.name', function ($view) {
$basket = ...// Your basket query here
$view->with('basket', basket);
});
This basically says, when view with name your.layout.name is composed, add variable with name $basket.
Related
I have a html form inside one of my views that is supposed to get an image the user uploads and save it, the form is below:
<form class="col-lg-12" action="/banner/store/">
The form itself is quite large, but later on there's a to end it. It was supposed to redirect me to the banner/store where my Banner controller have a dd() function so I can confirm everything is okay. But instead, I get a blank white screen and the url goes banner/store/?.
The routes to the BannerController seems to be correct since banner/create works, the problem is when I go from create to store, but anyways, here's how I set the Routes:
Route::resource('banner', 'BannerController');
Any ideas why my banner/store won't work? And why is there a question mark on the end of the url? Sorry if this may be a dumb error, I'm still learning coding.
Your action is is wrong. When you use the resource static method then the store-url is the same as the GET url.
You can achive your goal with:
<form class="col-lg-12" action="{{ route('banner.store') }}" method="POST">
See more information in documentation.
When you updating your banner, you can't use the browser native form with PUT.
See in this document how laravel will handle that for you.
Simplified my main.blade.php template looks like this...
<html>
<head>
#inlcude("header")
#yield("addToHeader")
</head>
<body>
#yield("content")
#include("footer")
</body>
</html>
Let's say my controller points to login.blade.php and it provides addToHeader and content sections. When my footer is included, I'd like to append the addToHeader section but I just can't get it to work.
In my footer I have tried
#section("addToHeader")
#parent
This is the added content
#yield("addToHeader")
#stop
And variations of this.
Now, for the sake of doing it right and in hopes that I might not spend my resources on doing this the incorrect or inefficient way, here is what I am trying to accomplish by doing this...
When a user logs in every time they try to load a new page, I want the website to throw a message to the user (in my case I am actually "locking" the page down with a modal) that lets the user know he/she must finish setting up her profile before anything else can be done. Is there a controller or route that doesn't care which page/action is being requested and allows me to send extra data to the template - even if it is just $data["lockdown"]=true?
I don't know if it's the best way to do it but i would go for something like this.
Using a session variable to know if the user has to set-up his profile or not:
Session::put('profile_uncompleted',true);
You can set this variable when the user log-in for exemple.
Then on your main.blade.php you can check if you have to display your modal:
#if(Session::has('profile_uncompleted')
#include('modal')
#endif
Where modal contains your Html modal content.
I'm trying to use ember animated outlet (found here) and, I can not for the life of me get it to work, I understand that instead of using {{outlet}} I need to use {{animated-outlet}} and use {{link-to-aniamted}} instead but it seems to be switching like normal. I also know that I need to include the js after the ember.js and also I am including the css file it comes with, so I'm kind of stumped on this. :(
For my basic view, I'm using
<script type="text/x-handlebars" data-template-name="application">
<div class='wrapper'>
#include('includes.globals.header')
<div class='content row' id='content'>
{{animated-outlet}}
</div>
#include('includes.globals.footer')
#include('includes.js.navigation')
</div>
</script>
and my link looks like:
{{#link-to-animated 'index' animations="main:slideLeft"}} Home #{{/link-to-animated}}
So, is there something i'm missing? Do I need to add something in my app.js? IF you need more code or info, just ask and I will edit this question! Thanks a lot in advance! I'm new to ember, so please take it easy!
You need to specify 'name' in the animated-outlet helper.
{{animated-outlet name="main"}}
The readme explains it: https://github.com/billysbilling/ember-animated-outlet/blob/master/README.md#use-animated-outlet-instead-of-outlet
I have problem with including Joomla views. I have many views in my extension and I want to include another one in my Dialog.
How can I do it?
In my first view I have this code:
<div id="modalDostawca" title="Dostawcy">
<div id="wewM">
//in here i want to include view data/tmpl/default.php
</div>
</div>
What kind of extension is your extension? A module? A component?
If it's a component, what you are trying to include is a template for a view, not a view! (the view is the one with view.html.php). Create a view + template for what you are trying to see. I don't think Joomla! can call multiple views at the same time. If you can reuse code inside models (if this is your concern).
You can also include files the normal way, with include(...).
I have a basic cms that loads content into pages that have mustache tags to indicate where in the html code those contents will appear.
The contents are specified in a widget model which indicate which type of content is to be displayed, so for example, freetext with id. or another model and id. each one of those models will be displayed differently based on the model they are based on.
I can imagine this becoming and bit unwieldy, is there a way to have a separate folder to put those widgets in so that it doesn't clutter my main code.
Something like apotomo does on rails would be good, but for codeigniter.
A widget model? That is not so nice. Have you tried looking at PyroCMS?
https://github.com/pyrocms/pyrocms/blob/master/system/pyrocms/modules/widgets/libraries/Widgets.php
From the sound of it you may be more interested in our Plugins library (sounds like the same thing with a different name). It is set up with a MY_Parser and runs on top of Dan Horrigan's Simpletags implementation.
Either way this has all be done plenty. If you want some more specific tailored advice you might have to demo some of your code.
Create a folder inside application/views called widgets. Put your widgets inside that folder and create a separate file for each widget (d0h).
Next, you have 2 options (at least that i know of):
a.) Load the widgets into variables inside the controller, then pass them to the main/general view
$data['widget_twitter_feed'] = $this->load->view('widgets/twitter', '', false);
$data['widget_something'] = $this->load->view('widgets/something', '', false);
$this->load->view('my_main_view', $data);
b.) Load the widgets inside the main/general view itself
<html>
...
<div id="sidebar">
<?php $this->load->view('widgets/twitter'); ?>
</div>
...
<div id="footer">
<?php $this->load->view('widgets/something'); ?>
</div>
...
</html>