laravel-5.5

How to take all the words in one normal array from the database in the Laravel framework with a minimum waste of time?

别说谁变了你拦得住时间么 提交于 2019-12-03 17:26:32
I want to take all the words from the database into default array . I have more than 50,000 words in the database, and most likely this number is up to a million. Therefore, I want this operation did not take much time. I tried such ways in which not a word is put into the usual array. That is, the words are passed to the associative array: $words = DB::table('words')->pluck('word'); dump($words); Result: Collection {#197 ▼ #items: array:12 [▼ 0 => "тоҷик" 1 => "ӯзбек" 2 => "қирғиз" 3 => "эрон" 4 => "япон" 5 => "англис" 6 => "тоҷик" 7 => "ӯзбек" 8 => "қирғиз" 9 => "эрон" 10 => "япон" 11 =>

Laravel How to remove “api” Prefix from subdomain URL

非 Y 不嫁゛ 提交于 2019-12-03 14:47:07
I have created a Laravel application which is both Web application and provides REST APIs to android and iOS platforms. I have two route files one is api.php and other is web.php and routes\api.php routing as follows: routes/api.php Route::group([ 'domain'=>'api.example.com', function(){ // Some routes .... } ); and nginx serve blocks configured can be seen here server { listen 80; listen [::]:80; root /var/www/laravel/public; index index.php; server_name api.example.com; location / { try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi

How to get current user in Laravel API using Passport?

房东的猫 提交于 2019-12-03 14:00:48
I am using passport package for Laravel API Authentication. When I post data I get error: 401 Unauthorized","error":{"error":"Unauthenticated."}. I use Auth::user()->id; to get current user id. How to solve this error? This code helped me: auth()->guard('api')->user() The simplest format is auth('api')->user(); When you use Auth::user()->id in your function's body. You have not logged in before. Please call login api first to get token then set it to the next API call. 来源: https://stackoverflow.com/questions/48417970/how-to-get-current-user-in-laravel-api-using-passport

Getting error while installing laravel installer in window 10

≯℡__Kan透↙ 提交于 2019-12-03 12:47:53
I am using Windows 10 and composer is installed. When I try to install laravel installer globally using this command: composer global require laravel/installer [Composer\Downloader\TransportException] The "https://repo.packagist.org/packages.json" file could not be downloaded: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. It means package not downloaded. I am not using any proxy server. Composer diagnose result is listed below:

Customising Laravel 5.5 Api Resource Collection pagination

天涯浪子 提交于 2019-12-03 08:22:54
I have been working with laravel api resource. By default laravel provides links and meta as shown below. "links": { "first": "https://demo.test/api/v2/taxes?page=1", "last": "https://demo.test/api/v2/taxes?page=4", "prev": null, "next": "https://demo.test/api/v2/taxes?page=2" }, "meta": { "current_page": 1, "from": 1, "last_page": 4, "path": "https://demo.test/api/v2/taxes", "per_page": 2, "to": 2, "total": 8 } But I don't want this, insted i want something like "pagination": { "total": 8, "count": 8, "per_page": 25, "current_page": 1, "total_pages": 1 } I'm able to get this info but if I do

Laravel : Setting dynamic routes based on access control list

为君一笑 提交于 2019-12-03 07:26:21
问题 I am building REST API with JWT authentication and authorization with own logic. It's working perfectly. Now, I want to set the routes dynamically based on roles and permission. Suppose I have database structure like: Role: id | name 1 | school 2 | transport Permissions: id | name | controller | routes 1 | view-class-result | ApiController | getClassResult 2 | view-student-result | ApiController | studentResult 3 | download-student-result | ApiController | donwloadSchoolTemplate Permission

How can I solve “laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system”?

僤鯓⒐⒋嵵緔 提交于 2019-12-03 05:45:56
问题 When I run composer install on command promp, there exist error like this : Problem 1 - Installation request for laravel/horizon v1.1.0 -> satisfiable by laravel/horizon[v1.1.0]. - laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system. To enable extensions, verify that they are enabled in your .ini files: - C:\xampp-7.1\php\php.ini You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode. How can I solve

Laravel The stream or file “/storage/logs/laravel.log” could not be opened: failed to open stream: Permission denied

走远了吗. 提交于 2019-12-03 00:42:26
I'm running Laravel app on server (Ubuntu 16.04). I have an error The stream or file "/var/www/mydomain.com/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied I've already google my question. I found this answer , but it wasn't helpful. I can't set 777 permission for storage (it's dangerous), as was suggested by many other answers I found. Any other suggestions? UPDATE: sudo chgrp -R www-data storage bootstrap/cache sudo chmod -R ug+rwx storage bootstrap/cache was helpful This commands were helpful: sudo chgrp -R www-data storage bootstrap/cache sudo chmod

Laravel : Setting dynamic routes based on access control list

狂风中的少年 提交于 2019-12-02 20:59:10
I am building REST API with JWT authentication and authorization with own logic. It's working perfectly. Now, I want to set the routes dynamically based on roles and permission. Suppose I have database structure like: Role: id | name 1 | school 2 | transport Permissions: id | name | controller | routes 1 | view-class-result | ApiController | getClassResult 2 | view-student-result | ApiController | studentResult 3 | download-student-result | ApiController | donwloadSchoolTemplate Permission_role role_id | permission_id 1 1 1 2 1 3 Now, I want to create routes according to roles and permission

Poor whereHas performance in Laravel

假如想象 提交于 2019-12-02 19:35:21
I want to apply a where condition to relation. Here's what I do: Replay::whereHas('players', function ($query) { $query->where('battletag_name', 'test'); })->limit(100); It generates the following query: select * from `replays` where exists ( select * from `players` where `replays`.`id` = `players`.`replay_id` and `battletag_name` = 'test') order by `id` asc limit 100; Which executes in 70 seconds. If I manually rewrite query like this: select * from `replays` where id in ( select replay_id from `players` where `battletag_name` = 'test') order by `id` asc limit 100; It executes in 0.4 seconds.