eloquent

Eloquent Validation for composite unique key

半世苍凉 提交于 2020-01-03 05:46:04
问题 I'm using Eloquent outside laravel framework from https://github.com/illuminate/database. The below is my composer file { "require": { "illuminate/database": "*", "illuminate/validation": "*", "dhorrigan/capsule": "*" } } And because of problem in Validator::make(). I'm using one of the suggested method in stackoverflow to use it like class Validator { protected static $factory; public static function instance() { if (!static::$factory) { $translator = new Symfony\Component\Translation

Laravel Eloquent query build select min value

旧城冷巷雨未停 提交于 2020-01-03 05:37:16
问题 I am having the following query (trimmed) to list the rooms to user for booking: $buildquery=Room:: with(['hotel' => function ($query) { $query->where('status', 0); }]) ->with('image')->with('amenities'); if ($request->filled('location_id')) { $buildquery->Where('city', $request->location_id); } $buildquery->Where('astatus', 1)->Where('status', 0); $rooms = $buildquery->simplePaginate(20); Actual query (not trimmed): select `rooms`.*, (select count(*) from `amenities` inner join `amenities

How can I update image in edit view in laravel?

筅森魡賤 提交于 2020-01-03 05:13:42
问题 In laravel I have a field in my edit view named Profile Picture, whenever I click On edit button I got all the values from database in edit view but I don't get image, And If whenever I click on submit button everytime I have to upload image without that I can't process further I want If I not upload new image then form will automatic consider old profile pic my blade file is like <div class="col-md-6"> <div class="form-group"> <label for="photo">Profile Picture :<span class="danger">*</span>

How can I update image in edit view in laravel?

一世执手 提交于 2020-01-03 05:13:07
问题 In laravel I have a field in my edit view named Profile Picture, whenever I click On edit button I got all the values from database in edit view but I don't get image, And If whenever I click on submit button everytime I have to upload image without that I can't process further I want If I not upload new image then form will automatic consider old profile pic my blade file is like <div class="col-md-6"> <div class="form-group"> <label for="photo">Profile Picture :<span class="danger">*</span>

Reload Page with Javascript after Database changes

荒凉一梦 提交于 2020-01-03 03:00:19
问题 I'm displaying a Table from a Database like so <tr> <td>{{ $user->id }}</td> <td>{{ $user->... }}</td> <td>{{ $user->... }}</td> <td>{{ $user->... }}</td> <td>{{ $user->... }}</td> <td>{{ $user->... }}</td> <td>{{ $user->... }}</td> <td>{{ $user->... }}</td> <td>{{ $user->... }}</td> <td>{{ $user->... }}</td> <td>{{ $user->... }}</td> <td></td> </tr> If something changes in the Database I have to hit F5 in the Browser to Display the changes. Now I want to refresh the Page with Javascript,

Pagination with Twig and Eloquent-5.2

走远了吗. 提交于 2020-01-03 02:08:56
问题 After following this video tutorial on building a PHP Authentication System with Slim/Twig and Eloquent 5.2. I have finished the video tutorial and have a working system. But I am failing to add pagination to the all user list on the 25th episode of the tutorial. Everything seems to work fine. but when I press page 2,3,4,etc... I am still getting the page 1 data. Here is the code I have so far: routes/user/all.php $app->get('/users', $authenticated(), function() use ($app) { $users = $app-

Laravel eloquent firstOrNew method doesn't update or insert

六月ゝ 毕业季﹏ 提交于 2020-01-02 10:19:33
问题 I have a problem with firstOrNew() method of the Laravel eloquent class. the problem is that when I give the method some attributes and values and call save() on the model, it doesn't get saved (inserted or updated). PHP : <? $flightModel = Flight::firstOrNew([ 'arrival' => $flightData['arrival'], 'plane' => $flightData['plane'] ]); $flightModel->departure = $flightData['departure']; $flightModel->save();//this doesn't save any data But when I try this with a new model it gets saved : <?

Laravel - Many-to-Many polymorphic relationships

﹥>﹥吖頭↗ 提交于 2020-01-02 08:48:48
问题 I'm banging my head against a polymorphic relationship definition within Laravel 5.7 Here's the data situation: I have a model for Users, a model for Products and a model for Merchandising I basically want to build a WishList for my user, that can contain both Merchandises and Products, and I want to have a polymorphic relationship there because I will have to add new types of things to sell at a later time. In my (simplified) current data schema, I have users -email -id products -id -name

Parameterized query binding in ON clause for a LEFT JOIN in Laravel Eloquent / Query Builder

穿精又带淫゛_ 提交于 2020-01-02 06:41:09
问题 Let's say I want to show a full list of awards with type="color": Awards Type 2013 Winner ====== ==== =========== Blue Award color Tom Red Award color Green Award color Dan To achieve this result I could have a query in Laravel like this: $year = '2013'; $awards = DB::table('awards') ->leftJoin('winners', function($join) use ($year) { $join->on('awards.id','=','winners.award_id'); $join->on('winners.year','=',DB::raw("'".$year."'")); } ->where('awards.type','color') ->get(); If you output the

Is it possible add tinyInteger or smallInteger to increments on laravel ORM?

好久不见. 提交于 2020-01-02 06:15:10
问题 Is possible to add that code or something like that to laravel\Illuminate\Database\Schema\Blueprint to use with migrations? public function incrementsTiny($column) { return $this->unsignedTinyInteger($column, true); } public function incrementsSmall($column) { return $this->unsignedSmallInteger($column, true); } scenario: some temp table that don't grow high and have some useful information or just small table that do not have more than 100 lines and need some rare update (add or just change)