laravel-5.1

'Where like' clause using the concatenated value of 2 columns with eloquent

不打扰是莪最后的温柔 提交于 2020-01-01 12:30:37
问题 I have a query that searches for a term in several columns and one of them has to be a full name. I have separated the full name in name and lastname, so I have to concat these 2 values when searching. I have this right now only searching for name. How I would add the concat to lastname? I was investigating over mutators but I don't know if it is the way to way. public function search($searchQuery) { $search = "%{$searchQuery}%"; return Order::with('customer') ->orWhereHas('customer',

Laravel 5 Seeder - multiple rows in DB

倖福魔咒の 提交于 2020-01-01 10:14:09
问题 I was wondering if it's possible to insert multiple rows like this (or something like this): <?php use Illuminate\Database\Seeder; class SettingTableSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { DB::table('settings')->insert( [ 'key' => 'username', 'value' => 'testusername' ], [ 'key' => 'password', 'value' => 'plain' ] ); } } I have a table settings in my database with columns key & value . The problem with the code above is that he only

Laravel 5.1 @can, how use OR clause

旧时模样 提交于 2020-01-01 03:53:06
问题 I did not find how to use a clause (OR, AND) in view with @can, for checking multiple abilities ... I tried: @can(['permission1', 'permission2']) @can('permission1' or 'permission2') @can('permission1' || 'permission2') But dont work ;( 回答1: You can use the Gate facade: @if(Gate::check('permission1') || Gate::check('permission2')) @endif 回答2: The @canany blade directive has been added to Laravel v.5.6.23 on May 24, 2018 Usage: @canany(['edit posts', 'delete posts']) <div class="actions"> @can

get file name without extension in laravel?

醉酒当歌 提交于 2020-01-01 03:52:06
问题 I have used Input::file('upfile')->getClientOriginalName() to retrieve name of uploaded file but gives name with extension like qwe.jpg .How do I get name without extension like qwe in laravel. 回答1: Laravel uses Symfony UploadedFile component that will be returned by Input::file() method. It hasn't got any method to retrive file name, so you can use php native function pathinfo() : pathinfo(Input::file('upfile')->getClientOriginalName(), PATHINFO_FILENAME); 回答2: You could try this $file =

How to capitalize first letter in Laravel Blade

北城余情 提交于 2020-01-01 01:10:45
问题 I'm using laravel (5.1) blade template engine with the localization feature. There is a language file messages.php within the /resources/lang/en/ folder: return [ 'welcome' => 'welcome', In my blade template the welcome message is called using the trans method: {{ trans('messages.welcome') }} In some cases I need to show the same message but with first letter capitalized ("Welcome"). I don't want to use duplicate records in the translation file. How can I approach this? 回答1: Use PHP's native

how to access protected array values ?

前提是你 提交于 2019-12-30 17:31:23
问题 Hi I have this array and I am not sure how will I fetch the name , brand, image, token values from it? Gloudemans\Shoppingcart\CartCollection Object ( [items:protected] => Array ( [1264477c2182cc04a63fde1186741fa7] => Gloudemans\Shoppingcart\CartRowCollection Object ( [associatedModel:protected] => [associatedModelNamespace:protected] => [items:protected] => Array ( [rowid] => 1264477c2182cc04a63fde1186741fa7 [id] => 1 [name] => washington apples [qty] => 1 [price] => 90 [options] =>

Laravel: How to access session value in AppServiceProvider?

放肆的年华 提交于 2019-12-30 17:25:26
问题 Is there any way available to access Session values in AppServiceProvider ? I would like to share session value globally in all views. 回答1: You can't read session directly from a service provider: in Laravel the session is handled by StartSession middleware that executes after all the service providers boot phase If you want to share a session variable with all view, you can use a view composer from your service provider: public function boot() { view()->composer('*', function ($view) { $view

laravel 5.1 error in validating doc docx type file

左心房为你撑大大i 提交于 2019-12-30 07:04:23
问题 Hi i am facing a docx type validation problem. I tried $validator = Validator::make($request->all(), [ 'resume' => 'mimes:doc,pdf,docx' ]); It will upload pdf file with no error but whenever i try to upload docx files it gives validation error 'must be a file of type: doc, pdf, docx' any idea 回答1: thanks solved it by allowing zip $validator = Validator::make($request->all(), [ 'resume' => 'mimes:doc,pdf,docx,zip' ]); this is because https://en.wikipedia.org/wiki/Office_Open_XML 回答2: In

laravel Expected response code 250 but got code “530”

会有一股神秘感。 提交于 2019-12-29 07:42:37
问题 Im trying to Mail in Laravel 5.1 my mail.php code is return [ 'driver' => env('MAIL_DRIVER', 'smtp'), 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 'port' => env('MAIL_PORT', 587), 'from' => ['address' => 'myemail@gmail.com', 'name' => 'sample'], 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 'username' => env('MAIL_USERNAME'), 'password' => env('MAIL_PASSWORD'), 'sendmail' => '/usr/sbin/sendmail -bs', 'pretend' => env('MAIL_PRETEND', false), ]; my .env file is MAIL_DRIVER=smtp MAIL_HOST

NotFoundHttpException in RouteCollection.php line 161 in laravel

冷暖自知 提交于 2019-12-29 01:58:06
问题 I added the following routes in routes.php : Route::get('/', function () { return 'Hello World'; }); Route::get('user/{id}', function ($id) { return 'User '.$id; }); Route::post('foo/bar', function () { return 'Hello World'; }); Route::put('foo/bar', function () { // }); Route::delete('foo/bar', function () { // }); And I am getting this error when I browse to /laravel/user/5/ Sorry, the page you are looking for could not be found. NotFoundHttpException in RouteCollection.php line 161:1) in