laravel

How to export csv file with shift-jis encoding in laravel?

偶尔善良 提交于 2021-01-28 11:11:02
问题 I am using laravel-excel to export csv file. To export, the code is like below, return Excel::download(new Export(results,$header), "test.csv"); And the Export.php file is like, namespace App\AllClass; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\Exportable; use Maatwebsite\Excel\Concerns\WithHeadings; class Export implements FromCollection,WithHeadings { private $myArray; private $header; public function __construct($myArray,$header){ $this->myArray =

Laravel 5.4 Raw Join Query

江枫思渺然 提交于 2021-01-28 10:01:47
问题 I have a table TBL_POST used to store blog posts. A post can be assigned to multiple categories, there is a column, cat_id that stores category ID's in comma separated pattern like 2,4,6 . I want to use FIND_IN_SET() method in this line ->leftJoin(TBL_CAT.' as c', 'p.cat_id', '=', 'c.id') to show the associated category names. How can I do that? public static function getPostWithJoin($status="") { $query = DB::table(TBL_POST .' as p') ->select('p.id','p.post_title','p.post_status','u.name as

Laravel 5.4 Raw Join Query

折月煮酒 提交于 2021-01-28 09:55:12
问题 I have a table TBL_POST used to store blog posts. A post can be assigned to multiple categories, there is a column, cat_id that stores category ID's in comma separated pattern like 2,4,6 . I want to use FIND_IN_SET() method in this line ->leftJoin(TBL_CAT.' as c', 'p.cat_id', '=', 'c.id') to show the associated category names. How can I do that? public static function getPostWithJoin($status="") { $query = DB::table(TBL_POST .' as p') ->select('p.id','p.post_title','p.post_status','u.name as

Network request failed in react native expo

余生长醉 提交于 2021-01-28 09:52:42
问题 im using expo in react native.i have a problem when post data to api laravel.its say"Network Request Failed".heres my code: i hope you can help me guys thankyou.enter image description here 回答1: I see that your fetch URL is served using an HTTP endpoint. You can only make requests to HTTPS endpoints from react-native projects. A possible workaround is to use ngrok. Just download it and run: ./ngrok http 8000 Since your port number is 8000. It will expose an HTTPS endpoint and replace your

Laravel 5.4 required if validation issue

两盒软妹~` 提交于 2021-01-28 09:50:52
问题 I have 2 fields, accepts_usd and price_usd. For price usd I have a validation rule: 'price_usd'=>'integer|required_if:accepts_usd,1', And for accepts_usd: 'accepts_usd'=>'boolean|required', When I want to store data if I set accepts_usd to false it still asks for price_usd. whats the issue here? What am I doing wrong? 回答1: you need to change your code to 'price_usd'=>'integer|required_if:accepts_usd,==,1', 回答2: From laravel docs: required_if:anotherfield,value,... The field under validation

Network request failed in react native expo

瘦欲@ 提交于 2021-01-28 09:49:42
问题 im using expo in react native.i have a problem when post data to api laravel.its say"Network Request Failed".heres my code: i hope you can help me guys thankyou.enter image description here 回答1: I see that your fetch URL is served using an HTTP endpoint. You can only make requests to HTTPS endpoints from react-native projects. A possible workaround is to use ngrok. Just download it and run: ./ngrok http 8000 Since your port number is 8000. It will expose an HTTPS endpoint and replace your

Laravel 5.4 required if validation issue

非 Y 不嫁゛ 提交于 2021-01-28 09:43:28
问题 I have 2 fields, accepts_usd and price_usd. For price usd I have a validation rule: 'price_usd'=>'integer|required_if:accepts_usd,1', And for accepts_usd: 'accepts_usd'=>'boolean|required', When I want to store data if I set accepts_usd to false it still asks for price_usd. whats the issue here? What am I doing wrong? 回答1: you need to change your code to 'price_usd'=>'integer|required_if:accepts_usd,==,1', 回答2: From laravel docs: required_if:anotherfield,value,... The field under validation

How to add extra data in response if Validation fails in FormRequest Laravel

試著忘記壹切 提交于 2021-01-28 09:31:05
问题 I need to add custom tag in response if the validation fails in FormRequest. <?php namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; class StoreMessage extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return true; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ 'name' => 'required|max:100', 'email' => 'required|email'

Laravel sort conversations by last message

跟風遠走 提交于 2021-01-28 09:29:50
问题 I have a Conversation model that has many ConversationMessage models. Now I want to sort the conversations based on the last message of the conversation. Basically like WhatsApp. How do I build the query? As a sidenote to my code: Conversation contains a user ( user_id ) and a company associated ( company_id ). Company has a belongsToMany relation to user. Conversation::whereHas('company', function ($q) use ($userId) { $q->whereHas('users', function ($q1) use ($userId) { $q1->where('users.id'

How to add extra data in response if Validation fails in FormRequest Laravel

空扰寡人 提交于 2021-01-28 09:28:52
问题 I need to add custom tag in response if the validation fails in FormRequest. <?php namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; class StoreMessage extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return true; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ 'name' => 'required|max:100', 'email' => 'required|email'