laravel-5.2

Laravel 5.2 how to use config::set in middleware

自古美人都是妖i 提交于 2019-12-10 18:34:02
问题 I want to use config::set in my Middleware for the set the value globally. But it is generating error. Below is the code which I am using public function handle($request, Closure $next, $guard = 'admin') { if (!Auth::guard($guard)->check()) { return redirect('/admin/login'); } //dd(Auth::guard('admin')->user()->id); $admin = $this->admin->with('adminRole')->find(Auth::guard('admin')->user()->id); config::set('bmc.admin_permission', $admin); // check user roles if (array_key_exists('0', $admin

How to update multiple rows from a single query using eloquent/fluent?

淺唱寂寞╮ 提交于 2019-12-10 16:58:45
问题 I was learning about How to insert multiple rows from a single query using eloquent/fluent and I found the answer here Can somebody share any documentation about how to update bulk rows in single query? My queries are below. Update tblrole set role = 'Super Admin' where RoleID = 1; Update tblrole set role = 'Super Admin A' where RoleID = 2; Update tblrole set role = 'Super Admin B' where RoleID = 3; Update tblrole set role = 'Super Admin C' where RoleID = 4; 回答1: You cannot do anything like

Laravel Illegal operator and value combination Exception on with() with belongsTo() relation

风格不统一 提交于 2019-12-10 15:26:49
问题 I have a Call Model with a belongsTo() relation as following class Call extends Model { public function campaign() { $callStart = $this->call_start; return $this->belongsTo('App\Campaign','gsm_number','gsm_number') ->where(function($query) use($callStart){ $query->where('end_date','=','0000-00-00 00:00:00') ->orWhere('end_date','>=',$callStart); })->where(function($query) use($callStart){ $query->where('start_date','=','0000-00-00 00:00:00') ->orWhere('start_date','<=',$callStart); }); } }

Skip and take all?

耗尽温柔 提交于 2019-12-10 14:44:48
问题 In eloquent, how can I skip 10 rows and then get the rest of the table? User::skip(10)->all(); The above does not work, but it gives you an idea what I am looking for. 回答1: Try this: $count = User::count(); $skip = 10; User::skip($skip)->take($count - $skip)->get(); With one query: User::skip($skip)->take(18446744073709551615)->get(); It's ugly, but it's an example from official MySQL manual: To retrieve all rows from a certain offset up to the end of the result set, you can use some large

Laravel 5.2 {{ env('APP_ENV') }} does not work in production

倾然丶 夕夏残阳落幕 提交于 2019-12-10 14:32:14
问题 The following code works on my development environment (Ubuntu 14.04 desktop) @if(env('APP_ENV') === 'production') // ... something But for some reason, the blade views on production (ubuntu 14.04 server) aren't getting the env variables. If I run php artisan env the response is just fine: Current application environment: production The database connection works fine. And the env() helper called from the controllers, also works. What I tried so far: php artisan clear:cache php artisan config

Laravel 5.2 : No hint path defined for [flash]

匆匆过客 提交于 2019-12-10 13:42:17
问题 After installed "laracasts/flash": "^1.3" package, I am trying to make a view and this is my code: @include('gazett.errors') Where in gazett.errors blade.php file code is here : <div class="row"> <div class="col-md-7 col-md-push-3" style="padding: 5px 24px!important;"> @include('flash::message') @if($errors->any()) <ul class="alert alert-danger text-center rtl ur fsize26" style="list-style: none;"> @foreach($errors->all() as $error) <li style="color: #000 !important;"> {{ $error }} </li>

How to encrypt laravel 5.2 URL or Routes?

回眸只為那壹抹淺笑 提交于 2019-12-10 13:37:38
问题 I need to encrypt routes in this URL? Because I do not want user to access URL by changing the item id. For example, user can change /items/1234 to /item/5678. Although item 1234 and 5678 belong to the same user, I still want to restrict the behavior. What I am trying to do is encrypting the routes but I am not sure whether this is a proper way or not. Any suggestions? 回答1: You can encrypt your url parameter and decrypt it in your controller. You can try this: In your view: Suppose your

Secure Asset/Media Folder through Auth Controller ? Laravel 5.2

不羁岁月 提交于 2019-12-10 12:56:45
问题 I have public/Asset/Media/folder I can access this file publicly like below. http://localhost/myapp/public/Asset/Media/1/phpunit.xml Similarly there are other folders in the Asset/Media folder which are being created on the fly. There are many files also present in those sub folder and are also present in Asset/Media folder Is there any way, such that if I try to access any file in Asset/Media folder or any file present in the sub folder of Asset/Media folder, I should be redirected to login

How to return 403 response in JSON format in Laravel 5.2?

房东的猫 提交于 2019-12-10 12:30:04
问题 I am trying to develop a RESTful API with Laravel 5.2. I am stumbled on how to return failed authorization in JSON format. Currently, it is throwing the 403 page error instead of JSON. Controller: TenantController.php class TenantController extends Controller { public function show($id) { $tenant = Tenant::find($id); if($tenant == null) return response()->json(['error' => "Invalid tenant ID."],400); $this->authorize('show',$tenant); return $tenant; } } Policy: TenantPolicy.php class

Cannot send message without a sender address in laravel 5.2 I have set .env and mail.php both

末鹿安然 提交于 2019-12-10 12:25:55
问题 In forgot password laravel sends email which gives error like : Swift_TransportException in AbstractSmtpTransport.php line 162: Cannot send message without a sender address i already have set my mail account details in .env and mail.php both. My .env : MAIL_DRIVER=smtp MAIL_HOST=smtp-mail.outlook.com MAIL_PORT=587 MAIL_USERNAME=raval_himanshu@live.in MAIL_PASSWORD=pass MAIL_ENCRYPTION=tls and my mail.php is <?php return [ 'driver' => env('MAIL_DRIVER', 'smtp'), 'host' => env('MAIL_HOST',