laravel

Get all posts and check if user liked each post

て烟熏妆下的殇ゞ 提交于 2021-01-28 21:55:11
问题 I'm trying to create an Eloquent query that fetches all posts and checks if the user liked each of those posts. I have the following models: Post.php class Post extends Eloquent { /** * The database table used by the model. * * @var string */ protected $table = 'posts'; public function user() { return $this->belongsTo('User'); } public function likes() { return $this->hasMany('Like'); } } Like.php : class Like extends Eloquent { /** * The database table used by the model. * * @var string */

Route is redirecting to wrong page

杀马特。学长 韩版系。学妹 提交于 2021-01-28 21:13:20
问题 I'm working on Laravel 5 and I've set up the routes for all the pages. I have a dashboard that has certain icons which when clicked redirects to different pages. Now, this particular icon "Total Applications" is when clicked doesn't redirect to the page associated with it, i.e., total.blade.php but instead redirects to another page candidate.blade.php. I'm new to Laravel. I want that when I click the "Total Applications" page it should redirect to the page designated for it. I'm sharing the

How @include works in blade templating in Laravel

て烟熏妆下的殇ゞ 提交于 2021-01-28 21:05:06
问题 I was curious about how @include works in Laravel Blade, I mean if we use it in a loop like this @foreach($posts as $post) @include('parts.post') @endforeach will we load this file x times where x is amount of posts or we load this file once and use it x times? Thanks 回答1: The blade template engine works by turning blade-html files into php-html files. @include will be replaced only once e.g. <!-- parts/post.blade.php --> <p>This is my post: {{$post}} </p> <!-- some-template.blade.php -->

How @include works in blade templating in Laravel

ⅰ亾dé卋堺 提交于 2021-01-28 20:41:09
问题 I was curious about how @include works in Laravel Blade, I mean if we use it in a loop like this @foreach($posts as $post) @include('parts.post') @endforeach will we load this file x times where x is amount of posts or we load this file once and use it x times? Thanks 回答1: The blade template engine works by turning blade-html files into php-html files. @include will be replaced only once e.g. <!-- parts/post.blade.php --> <p>This is my post: {{$post}} </p> <!-- some-template.blade.php -->

Running python script in Laravel Controller: “sh: 1: python: not found ”

╄→尐↘猪︶ㄣ 提交于 2021-01-28 19:46:30
问题 I am trying to run a python script in my Laravel PHP controller using Symfony Process. The python file is located in the public directory. The python file is: import requests URL = 'someURL.com' response = request.get(url); print(response) Here is my code in my PHP Controller: $process = new Process('python '.public_path('MyPython.py')); $process->run(); //executes after the command finishes if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } Log::error($process-

Get config in Routes?

喜欢而已 提交于 2021-01-28 19:44:38
问题 I want to prefix all my routes with a value from config but I am having trouble getting the value from the config file: Config::get('custom.routes.prefix'); The above gets null even though the value is set in the config file: //config/custom.php 'routes' => => [ 'prefix' => 'whatever', ], How can I get access to config in routes.php? Edit Please note this is not how a question about how to prefix routes, it's how to prefix them with a value from config. 回答1: Maybe just store the route name in

Laravel Eloquent. I try to intersect two intermediate table. Is there any query more efficient than this?

谁都会走 提交于 2021-01-28 19:35:48
问题 Laravel Eloquent. I try to intersect two intermediate table. Is there any query more efficient than this ? Unit Model : public function products() { return $this->belongsToMany('App\Product'); } public function users() { return $this->belongsToMany('App\User'); } Product Model : public function units() { return $this->belongsToMany('App\Unit'); } public function users() { return $this->belongsToMany('App\User'); } User Model : public function units() { return $this->belongsToMany('App\Unit');

Image class not found when using Intervention

流过昼夜 提交于 2021-01-28 19:33:10
问题 I have installed Laravel 5.2 and Intervention, this is now in the composer.json file in the project. "require": { "php": ">=5.5.9", "laravel/framework": "5.2.*", "intervention/image": "^2.3" }, After reading tutorials, it mentions an Image.php file that should be in the config folder inside the project once you have installed Intervention. I believe I have installed Intervention correctly but when I try to use the Intervention functions it does not work. When I try to use this line of code I

Get a cookie in Laravel 5 middleware

不羁的心 提交于 2021-01-28 19:26:03
问题 I'm trying to retrieve a cookie from a middleware in Laravel 5.3 but it seems like $request->cookie('language') is empty. I'm guessing that it is only set after the middleware runs. I read somewhere that I should use \Cookie::queued('language'), but it's still empty. Is my only option using the $_COOKIE variable? 回答1: When do you set this cookie? Remember that cookies are stored in the browser, so the user needs to get the response in order for you to be able to retrieve the cookie later. You