blade

Laravel send variable to the view

主宰稳场 提交于 2019-12-20 05:47:12
问题 routes.php Route::post("/{user}/{char_name}", array( 'as' => 'char-profile-post', 'uses' => 'ProfileController@postDropDownList')); Route::get("/{user}/{char_name}", array( 'as' => 'char-profile-get', 'uses' => 'ProfileController@getDropDownList')); ProfileController.php public function postDropDownList($user, $char_name) { $user = Auth::user(); $char_name = Input::get('choose'); $char_name_obj = User::find($user->id)->characters()->where('char_name', '=', $char_name)->first(); return

Counting total posts by a user in the blade view

≡放荡痞女 提交于 2019-12-20 04:43:20
问题 I have sent a collection of all posts in my blog to my index view and then used the following code to count the total posts made by each user. <p class="joined-text">Posts: {{count(App\Posts::where('user_id', $post->user->id)->get())}}</p> Is this bad practice to do this from within the blade view? If it is how would I achieve this? Models class Posts extends Model { public function user() { return $this->belongsTo(User::class); } public function comments() { return $this->hasMany(Comments:

Laravel 5: Class 'HTML' not found

北城以北 提交于 2019-12-19 19:37:09
问题 I'm just getting started with Laravel. I'm in a controller method and I say: return \View::make('scrape', $data); Then in scrape.blade.php I have: @extends('layouts.master'); Finally, in layouts/master.blade.php I have: {{ HTML::style('css/bootstrap.min.css') }} And that where things seem to fall apart and I get: FatalErrorException in 002eb18bb71fd3ec1de058967b799d49 line 6: Class 'HTML' not found What am I doing wrong? Thanks for your help. 回答1: Searching on google I found this "By default

Laravel blade debug view name on error

∥☆過路亽.° 提交于 2019-12-19 10:27:59
问题 when there is some error in view, L4 shows a nice trace, but cached filename: open: /var/www/webpage/app/storage/views/1154ef6ad153694fd0dbc90f28999013 howto during view-rendering-to-cache save view's path/name (in a comment or something)? Or better yet - to show it in the debug-error-page (its called whoops or something?) Thanks ;) 回答1: One way to tackle this problem is add a html comments (not blade ones as they will not be rendered in compiled view) in sections which get echoed. @section(

How to break a foreach loop in laravel blade view?

女生的网名这么多〃 提交于 2019-12-19 05:05:13
问题 I have a loop like this: @foreach($data as $d) @if(condition==true) {{$d}} // Here I want to break the loop in above condition true. @endif @endforeach I want to break the loop after data display if condition is satisfied. How it can be achieved in laravel blade view ? 回答1: From the Blade docs: When using loops you may also end the loop or skip the current iteration: @foreach ($users as $user) @if ($user->type == 1) @continue @endif <li>{{ $user->name }}</li> @if ($user->number == 5) @break

Laravel Blade Template passing data to Vue JS component

我与影子孤独终老i 提交于 2019-12-19 01:35:09
问题 I am having a problem passing a property using Vuejs ~1.0 to a child component from a Laravel Blade template. If I pass something in plain text it works just fine, but when I try to pass a js property, array, or object it doesn't work at all. I currently have a blade file with a custom component which looks like this: <my-component video="@{{ stuff }}"></my-component> If I leave out the @{{ }} the only thing that will be passed is the string stuff , and if I leave out the @ , I obviously get

Laravel Blade: @endsection vs @stop

北战南征 提交于 2019-12-18 18:49:39
问题 In Laravel Blade, we can basically do this: @section('mysection') @endsection @section('mysection') @stop What is the difference between @stop and @endsection ? 回答1: The @endsection was used in Laravel 3 and it was deprecated in Laravel 4 In the Laravel 4 to end a section you have to use @stop You can refer the Changelog here http://wiki.laravel.io/Changelog_%28Laravel_4%29#Blade_Templating 回答2: Authoritative answer by Taylor Otwell @endsection became @stop in L4, just as @yieldSection became

Looping PHP Nested Arrays - Extract values into Blade Views (Laravel)

橙三吉。 提交于 2019-12-18 17:04:43
问题 I know there are many questions on this topic, but none quite deal with this (as far as I could see). I have a PHP array (which FYI, is returned via Guzzle response) in a Laravel Project. The PHP array $users = array(2) { ["error"]=> bool(false) ["spirits"]=> array(2) { [0]=> array(2) { ["id"]=> string(1) "1" ["name"]=> string(5) "Foo" } [1]=> array(2) { ["id"]=> string(1) "2" ["name"]=> string(3) "Bar" } } } I simply want to extract the "id" and "name" keys below, to use in a view but I'm a

How can I use HTML tags in a Laravel localization file?

≯℡__Kan透↙ 提交于 2019-12-18 13:52:32
问题 I'm trying to utilize Laravel's localization feature, but I need to be able to put emphasis or bolden a portion of a phrase. Inserting a HTML tag into the language file causes it to be escaped when outputted to a blade. For example, here is my language file entry: return [ 'nav' => [ 'find' => '<strong>Find</strong> Your Home', ] ]; When I call it from within a blade: (I've tried using triple braces as well.) {{ trans('base.nav.find') }} It outputs: <strong>Find</strong> Your Home I could

Displaying the Error Messages in Laravel after being Redirected from controller

匆匆过客 提交于 2019-12-18 11:03:17
问题 How can I display the validation message in the view that is being redirected in Laravel ? Here is my function in a Controller public function registeruser() { $firstname = Input::get('firstname'); $lastname = Input::get('lastname'); $data = Input::except(array('_token')) ; $rule = array( 'firstname' => 'required', 'lastname' => 'required', ) ; $validator = Validator::make($data,$rule); if ($validator->fails()) { $messages = $validator->messages(); return Redirect::to('/')->with('message',