laravel-5.2

How to return view with flash message?

非 Y 不嫁゛ 提交于 2020-05-13 06:50:05
问题 What i need is this: return view('protected.standardUser.includes.documents',compact('documents'))->with('successMsg','Property is updated .'); The i could use it like this: @if(Session::has('successMsg')) <div class="alert alert-success"> {{ Session::get('successMsg') }}</div> @endif Any suggestion? 回答1: It looks like you're mixing two different ways of passing data to a view, which I'm guessing is the problem. The documentation seems to indicate it's a one or the other type situation. You

Get file's signed URL from amazon s3 using Filesystem Laravel 5.2

让人想犯罪 __ 提交于 2020-05-09 18:01:46
问题 I'm looking for a good solution to get the signed url from amazon s3. I have a version working with it, but not using laravel: private function getUrl () { $distribution = $_SERVER["AWS_CDN_URL"]; $cf = Amazon::getCFClient(); $url = $cf->getSignedUrl(array( 'url' => $distribution . self::AWS_PATH.rawurlencode($this->fileName), 'expires' => time() + (session_cache_expire() * 60))); return $url; } I don't know if this is the best way to do with laravel, considering it has a entire file system

Laravel 5.2 - Left Join DB::Raw not working?

被刻印的时光 ゝ 提交于 2020-05-09 05:58:49
问题 I have the following query where I'm trying to use DB::Raw() for the left join but I'm getting error: Missing argument 2 for Illuminate\Database\Query\Builder::leftJoin() This is my query: return $this->model->from('alerts as a') ->leftJoin(DB::Raw("locations as l on l.id = JSON_UNQUOTE(JSON_EXTRACT(a.criteria, '$.locationId'))")) ->leftJoin(DB::Raw("industries as i on find_in_set(i.id, JSON_UNQUOTE(JSON_EXTRACT(a.criteria, '$.industries')))")) ->where('user_id', '=', $userId) ->selectRaw("a

Get all relations name in laravel5 model

↘锁芯ラ 提交于 2020-04-17 07:12:58
问题 I have model include of several relation for example like this: public function NewsCategory() { return $this->belongsTo("News\Model\NewsCategory"); } public function NewsImage() { return $this->belongsTo("News\Model\NewsImage"); } public function NewsTag() { return $this->belongsTo("News\Model\NewsTag"); } and relations create dynamically. How can I get all this class name? In this example I want NewsCategory,NewsImage,NewsTag 回答1: one approach is to as follows : $results = ModelClass::where

Force user to pick at least one checkbox - Laravel

与世无争的帅哥 提交于 2020-04-11 04:43:08
问题 How to validate if user has picked at least one checkbox by validating on the server side in Laravel 5.2 I have a simple select box: <label for="has_driverslicense">KFZ Führerschein: </label> <select class="form-control" required="required" id="has_driverslicense" name="has_driverslicense"> <option value="0">Nein</option> <option value="1">Ja</option> </select> and a hidden div: <div id="kfz" style="display: none;"> <div> <input id="checkbox-20" class="checkbox-style" name="B" type="checkbox"

Laravel Dynamic Fillable in Models

Deadly 提交于 2020-04-05 15:25:09
问题 Got stuck in a issue with laravel 5.2. Following is the error during eloquent create operation(post call), Mass Assignment Exception in Model.php 453: column_name Following are the prerequisites, which are to be taken into consideration: Fillables in model are filled in a dynamic manner by the following code: public function __construct() { $this->fillable(\Schema::getColumnListing($this->getTable())) } Following are the methods which are debugged till now: Before insertion, in controller,

Laravel check if collection is empty

拈花ヽ惹草 提交于 2020-04-05 07:45:41
问题 I've got this in my Laravel webapp: @foreach($mentors as $mentor) @foreach($mentor->intern as $intern) <tr class="table-row-link" data-href="/werknemer/{!! $intern->employee->EmployeeId !!}"> <td>{{ $intern->employee->FirstName }}</td> <td>{{ $intern->employee->LastName }}</td> </tr> @endforeach @endforeach How could I check if there are any $mentors->intern->employee ? When I do : @if(count($mentors)) It does not check for that. 回答1: You can always count the collection. For example $mentor-

Can not call Auth class inside Scope class in Laravel 5.2

末鹿安然 提交于 2020-03-26 21:35:59
问题 I added External Scope for User Model. Simply created Scope, with the name DeveloperScope use Illuminate\Database\Eloquent\Scope; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Auth; class DeveloperScope implements Scope { public function apply(Builder $builder, Model $model) { if(Auth::user()->id != 1){ $builder->where('id', '<>', 1); } } } Then, I called this scope for User model. User Model use Illuminate\Auth\Authenticatable; use Illuminate\Database

Can not call Auth class inside Scope class in Laravel 5.2

隐身守侯 提交于 2020-03-26 21:33:31
问题 I added External Scope for User Model. Simply created Scope, with the name DeveloperScope use Illuminate\Database\Eloquent\Scope; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Auth; class DeveloperScope implements Scope { public function apply(Builder $builder, Model $model) { if(Auth::user()->id != 1){ $builder->where('id', '<>', 1); } } } Then, I called this scope for User model. User Model use Illuminate\Auth\Authenticatable; use Illuminate\Database

Laravel 5 single route multiple controller method

不羁岁月 提交于 2020-03-19 05:09:32
问题 I have a route with parameter Route::get('forum/{ques}', "ForumQuestionsController@show"); Now I want a route something like Route::get('forum/add', ['middleware' => 'auth:student', 'uses' => "ForumQuestionsController@add"]); well when I hit localhost:800/forum/add I get routed to ForumQuestionsController@show instead of ForumQuestionsController@add Well I know I can handle this in show method of ForumQuestionsController and return a different view based on the paramter. But I want it in this