blade

Laravel 4 Blade @include variable

自古美人都是妖i 提交于 2019-12-03 04:26:34
I was trying to do include with Laravel blade, but the problem is it can't pass the variable. Here's my example code: file_include.blade.php <?php $myvar = "some text"; main.blade.php @include('file_include') {{$myvar}} When I run the file, it return the error "Undefined variable: myvar". So, how can I pass the variable from the include file to the main file? Thank you. Why would you pass it from the include to the calling template? If you need it in the calling template, create it there, then pass it into the included template like this: @include('view.name', array('some'=>'data')) Above code

How to comment code in a vue.js file?

南楼画角 提交于 2019-12-03 04:10:17
I have the need to insert a comment inside a vue.js file for future references, but I don't find how you do this in the docs. I have tried // , /**/ , {{-- --}} , and {# #} , but none of them seem to work. I am using Laravel's blade. So this is the sample_file.vue : <template> <div class="media"> <like-button :post="post" v-if="post.likedByCurrentUser === false && "></like-button> {{--I want to comment this but I get an error from the gulp watch: post.canBeLikedByCurrentUser === true--}} <div class="media-left"> <a href="#"> <img class="media-object" v-bind:src="post.user.avatar" v-bind:title=

Creating custom error page in Lumen

↘锁芯ラ 提交于 2019-12-03 03:20:41
How do I create custom view for errors on Lumen? I tried to create resources/views/errors/404.blade.php , like what we can do in Laravel 5, but it doesn't work. Errors are handled within App\Exceptions\Handler . To display a 404 page change the render() method to this: public function render($request, Exception $e) { if($e instanceof NotFoundHttpException){ return response(view('errors.404'), 404); } return parent::render($request, $e); } And add this in the top of the Handler.php file: use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; Edit: As @YiJiang points out, the response

How do I pass a variable to the layout using Laravel' Blade templating?

故事扮演 提交于 2019-12-03 01:28:29
问题 In Laravel 4, my controller uses a Blade layout: class PagesController extends BaseController { protected $layout = 'layouts.master'; } The master layout has outputs the variable title and then displays a view: ... <title>{{ $title }}</title> ... @yield('content') .... However, in my controller I only appear to be able to pass variables to the subview, not the layout. For example, an action could be: public function index() { $this->layout->content = View::make('pages/index', array('title' =>

laravel 5.2 How to get route parameter in blade?

非 Y 不嫁゛ 提交于 2019-12-03 01:16:15
this is my url http://project.dev/blogs/image-with-article so, here I need the parameter image-with-article in my blade to display which is a parameter named slug here is in my routes file I need the slug paramter in blade. Route::get('/blogs/{slug}', ['as'=>'blog.by.slug', 'uses'=> 'CmsController@show']); I'm not sure what you mean. If you're trying to construct the route in a Blade template, use <a href="{{ route('blog.by.slug', ['slug' => 'someslug']) }}">...</a> If you're trying to access the given parameter, I would suggest passing it from the controller: // CmsController public function

How to access URL segment(s) in blade in Laravel 5?

北战南征 提交于 2019-12-03 00:59:35
I have a url : http://localhost:8888/projects/oop/2 I want to access the first segment --> projects I've tried <?php echo $segment1 = Request::segment(1); ?> I see nothing print out in my view when I refresh my page. Any helps / suggestions will be much appreciated Aniket Singh Try this {{ Request::segment(1) }} DoubleJ The double curly brackets are processed via Blade -- not just plain PHP. This syntax basically echos the calculated value. {{ Request::segment(1) }} Here is how one can do it via the global request helper function. {{ request()->segment(1) }} Note: request() returns the object

Go back URL in Laravel 5.1

倖福魔咒の 提交于 2019-12-02 23:19:14
How can I get the previous URL visited on the website in Laravel 5.1? In Laravel 4 I just needed to write it like below: {{ URL::previous() }} The cleanest way seems to be using the url() helper: {{ url()->previous() }} URL::previous() works for me in my Laravel 5.1 project. Here is Laravel 5.1 doc for previous() method, which is accessible through URL Facade . You can still try alternatives, in your views you can do: {{ redirect()->getUrlGenerator()->previous() }} or: {{ redirect()->back()->getTargetUrl() }} 来源: https://stackoverflow.com/questions/32826887/go-back-url-in-laravel-5-1

What is the difference between Section and Stack in Blade?

瘦欲@ 提交于 2019-12-02 22:06:36
We can use a section to define some HTML and then yield that somewhere else. So why do we have stacks? https://laravel.com/docs/5.2/blade#stacks It's doing exactly the same thing with different keywords, but has fewer options (No inheritance). @push('scripts') <script src="/example.js"></script> @endpush <head> <!-- Head Contents --> @stack('scripts') </head> Can be done with section: @section('scripts') <script src="/example.js"></script> @endsection <head> <!-- Head Contents --> @yield('scripts') </head> macghriogair I might be mistaken, but the difference is not only semantically, but in

laravel which route or link should I use for this case

大兔子大兔子 提交于 2019-12-02 19:15:02
问题 I have an xmldocument model, which I can show its profile in this way: `public/xmldocument/4` From this page, there are three links, which are: add general information add master information add general information each of them is for a resource. for example: add general information is the create of the resource general_information add master information is the create of the resource master_information add general information is the create of the resource general_information But each of them

Laravel 4 Controller Templating / Blade - Correct method? [closed]

人盡茶涼 提交于 2019-12-02 18:08:37
I've been reading through the Laravel 4 documentation and have been making a demo application to help with learning. I couldn't find much documentation on the templating of views with blade and controllers. Which is the correct method or does it come down to personal preference? E.g. 1 Controllers/HomeController.php protected $layout = 'layouts.main'; public function showWelcome() { $this->layout->title = "Page Title"; $this->layout->content = View::make('welcome'); } Views/layouts/main.blade.php <html> <head> <title>{{ $title }}</title> </head> <body> {{ $content }} </body> </html> Views