laravel-5.3

Return Collection after update()?

﹥>﹥吖頭↗ 提交于 2019-12-03 15:35:43
Using Raw, how to return collection of updated row? For example: $updated = DB::table('users')->where('id', 1)->update(['votes' => 123]); I was expecting dd($updated) to return updated row of collection but it returned 1. {{$updated->votes}} should return 123 That's not how it works. You can't expect this query will return you an object: $updated = DB::table('users')->where('id', 1)->update(['votes' => 123]); If you want to use Query Builder only as you mentioned in your question, you'll need to get an object manually: $data = DB::table('users')->where('id', 1)->first(); With Eloquent you can

Multi-language indexes with Laravel Scout and Algolia

混江龙づ霸主 提交于 2019-12-03 13:28:30
How should I manage the multi-language indexes (For example: page / page_translations models should become page_en / page_fr indexes). I am using " Dimsav\Translatable " package. Page model : id, status_id, created_at, updated_at PageTranslation model : id, page_id, locale, title, slug, body Algolia offers support for this ( https://www.algolia.com/doc/guides/search/multilingual-search/ ) but I am not sure how to achieve this with Laravel Scout . The only solution that comes in my mind is to index both language rows (from the translations model) in the same index storing the locale and

Disable error reporting entirely in Laravel production?

纵饮孤独 提交于 2019-12-03 12:52:57
问题 I would like to disable error reporting entirely on production, because we have some very old code we still need to fix but for now does work (yes I don't like it either). We cannot fix everything in a few days, so we need to just supress the warnings and exceptions like we always did. The real problem is that it already throws an exception on a simple lazy bug like (because var is not defined) if(!$var) { // do whatever } tried APP_DEBUG=false APP_LOG_LEVEL=emergency display_errors(false);

Laravel 5.3 storage:link -> symlink(): Protocol error

非 Y 不嫁゛ 提交于 2019-12-03 11:25:04
问题 I'm trying to run the following artisan command: php artisan storage:link I get this error: [ErrorException] symlink(): Protocol error Can you help me to solve this. This is my setup: Windows 10 using vagrant with Homestead (v0.5.0) box Ubuntu 16.04 LTS (GNU/Linux 4.4.0-22-generic x86_64) Laravel Framework version 5.3.6 PHP 7.0 回答1: Your problem probably is that you have to start your vagrant box as a system administrator. So hit start type "cmd", right click it choose "Run as administrator".

Laravel Passport Password Grant - Client authentication failed

╄→гoц情女王★ 提交于 2019-12-03 10:54:52
问题 After hearing a lot about laravel passport, i thought of implementing it into my new project where my requirement is to create an API that'll be used in a mobile app. So my mobile app is a client , which will further have its users. I followed the steps mentioned by Taylor and also read about it here. In a nutshell I followed these steps: Installed laravel/passport . Created a website user. Generated passport keys php artisan passport:install Generated client_id and client_secret using php

Laravel 5.3 date validator: equal to or after start_date

一世执手 提交于 2019-12-03 10:51:16
I'm using Laravel 5.3 to validate start_date and end_date for an event. end_date should be equal to start_date or the after date. end_date >= start_date $validator = Validator::make($data, [ 'start_date' => 'required|date', 'end_date' => 'required|date|after:start_date', ]); I tried to use after , but it only works for end_date > start_date. Of course, I can add custom rule using Validator::extend , but I'd like to know if we can do without adding custom rule. Is there any way to add negative rule or add >= rule? Thanks Sujiraj R $validator = Validator::make($data, [ 'start_date' => 'required

api or web Laravel 5.3

自作多情 提交于 2019-12-03 10:11:27
I have a question that might sound silly to you so please forgive me. I am not sure when do I use the routes/api.php file. If I want to delete a record from a datatable with ajax, do I need to create a separate controller and put the route in api.php or can I use the same controller I use for everything else and put the route in web.php? bernadd I'm not sure if you read the Laravel documentation or how much familiar you are with Laravel, but in Laravel 5.3 you have web routes and api routes in separate files. You use api routes only for registering your api (ie if you are building a rest api

Laravel 5.3 Validation Fails when Variables are Null

耗尽温柔 提交于 2019-12-03 09:59:40
Since upgrading laravel from 5.1 to 5.3, I've got couple of odd issues with Validation. When I post a data like this: firstName null And the validation rules are like this: $validator = Validator::make($postData, [ 'firstName' => 'string|max:255', 'lastName' => 'string|max:255' ]); The above fails with the messages something like "The XYZ must be a string." . What I don't understand is: Why is the validation failing when it is not set as required ? Meaning, it should ignore it and not throw an error if the value is empty, right? Why does the validation fail if the value is set as null ? Why

Ajax File Upload With Form Data Laravel 5.3

五迷三道 提交于 2019-12-03 08:55:17
i want to upload a profile image of a user to the server and i'm stuck at ajax upload of image all my form data are posting to database including the image name but the file is not uploading to the server my view is //form <form id="example-form" method="post" enctype="multipart/form-data"> {!! csrf_field() !!} <div class="row"> <div class="col m12"> <div class="row"> <div class="input-field col m12 s12"> <input id="name" name="name" type="text" placeholder="Full Name" class="required validate"> </div> <div class="input-field col s12"> <input id="email" name="email" type="email" placeholder=

Read and replace contents in .docx (Word) file

五迷三道 提交于 2019-12-03 08:21:46
I need to replace content in some word documents based on User input. I am trying to read a template file (e.g. "template.docx"), and replace First name {fname}, Address {address} etc. template.docx: To, The Office, {officeaddress} Sub: Authorization Letter Sir / Madam, I/We hereby authorize to {Ename} whose signature is attested here below, to submit application and collect Residential permit for {name} Kindly allow him to support our International assignee {name} {Ename} Is there a way to do the same in Laravel 5.3? I am trying to do with phpword, but I can only see code to write new word