laravel-5.3

Laravel 5.3 Eloquent Relationships

懵懂的女人 提交于 2019-12-25 08:50:15
问题 i'm using Laravel 5.3 and i'm trying to select from the database the values for the lang files, i created a file and named it global.php and inside the file i tried to do this: use App\Dictionary; $language_id = 1; $dictionary = array(); $lables = Dictionary::where('language_id',$language_id)->get(); foreach($lables as $label): $dictionary[$label->label] = $label->value; endforeach; return $dictionary; now, this is working but i want to select the rows using the short_name field and not the

Constraining eager loaded relationship

自作多情 提交于 2019-12-25 08:15:10
问题 I found a very bizarre behavior of with function for overloading relationships. I have Product and Deal relationships, such that Product belongsTo() Deal (through product_id in deals table). Now, when I try to get all products on sale: Product::with(['deal' => function($query) { $query->whereDate('ends_at', '>', Carbon::now()->toDateTimeString()); }])->get() this returns a collection of all products, even though there are no records in deals table and all products have deal_id set to NULL .

Why broadcasting channel public not working? Laravel

余生长醉 提交于 2019-12-25 01:03:10
问题 I use laravel 5.3 I make routes/channels.php like this : <?php Broadcast::channel('messages', function() { return true; }); If I input the data cart and click submit, it will run this : this.$http.post(window.BaseUrl + '/guest/add-notification', {cart_data: JSON.stringify(data)}); It will call function on the controller The function like this : public function addNotification(Request $request){ $input = $request->only('cart_data'); $data = json_decode($input['cart_data'], true); event(new

How can I add condition based on the parameters of the array data on the rules Laravel?

瘦欲@ 提交于 2019-12-24 20:02:22
问题 I use Laravel 5.3 My rules Laravel like this : <?php namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; class AddCartRequest extends FormRequest { public function rules() { return [ 'product_id'=>'required|numeric', 'delivery_address'=>'required', 'request_delivery_at' => 'required|date_format:d-m-Y H:i:s|after:120 minutes' ]; } } The result of echo '<pre>';print_r($this->request->get('delivery_address'));echo '</pre>'; like this : Array ( [sender_name] => chelsea

Shopify: How to delete database entry fast after uninstall web-hook response, so the merchant uninstall and re-install quickly?

孤者浪人 提交于 2019-12-24 19:23:13
问题 This is my code in callbackController.php file $url = 'https://' . $_GET['shop'] . '/admin/webhooks.json'; $webhookData = [ 'webhook' => [ 'topic' => 'app/uninstalled', 'address' => config('app.url').'uninstall.php?shop='.$shop, 'format' => 'json' ] ]; $uninstall = $sh->appUninstallHook($accessToken, $url, $webhookData); This is my uninstall.php file code , these file is in laravel root folder. $connection = new mysqli("localhost", "username", "******", "database"); $delete_shop = "DELETE

how to make validation using ajax Laravel 5.3

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 09:28:47
问题 I am using Laravel 5. In my OrganisationsController I have a method addItem public function addItem(Request $request) { $rules = array( 'nom' => 'required', ); // for Validator $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) return Response::json(array('errors' => $validator->getMessageBag()->toArray())); else { $section = new Section(); $section->nom = $request->nom; $section->save(); return response()->json($section); } } Ajax code $("#add").click(function() { $

Problems getting success or done response in $.ajax when using vue.js in Laravel

旧巷老猫 提交于 2019-12-24 08:30:49
问题 I have this simple form where the user should only type text inside a textarea. When the user clicks on the submit button, inside the javascript, I make a call with vue and ajax to insert that text into the database. My problem is that, right after the user clicks on submit, I want the textarea to be cleared, but after the text has been saved into the database, the text is still there. It persists. Since I am using vue.js and ajax, there is this .done (success) callback function I am waiting

Automatically run specific tests on file change?

限于喜欢 提交于 2019-12-24 07:27:12
问题 I'm looking for a way to automatically run specific tests when specific files are changed, similar to what you can do with a Guardfile in Ruby on Rails . I was wondering if there is a way to do this with Laravel Elixir or with gulp (I.e. gulpfile.js ) Here is an example of what I'm looking for: watch('^app/Http/Controllers/(.+)(Controller)\.php$', function($match) { return ["tests/{$match[1]}"]; }); watch('^app/Policies/(.+)(Policy)\.php$', function($match) { return ['tests/' . str_plural(

Route precedence order

五迷三道 提交于 2019-12-24 01:54:43
问题 I have 2 routes with their methods written in same controller[LinkController]: Route::get('/{country}/{category}', ['as' => 'tour.list', 'uses' => 'LinkController@tourlist']); Route::get('/{category}/{slug}',['as' => 'single.tour', 'uses' => 'LinkController@singleTour']); And my methods are: public function tourlist($country, $category) { $tour = Tour::whereHas('category', function($q) use($category) { $q->where('name','=', $category); }) ->whereHas('country', function($r) use($country) { $r-

Laravel 5 eager loading dropping leading zeros from foreign key

落花浮王杯 提交于 2019-12-24 01:17:41
问题 I believe that I've encountered a bug in how Laravel 5.3 handles eager loading when the foreign key is a string which contains zerofilled numbers. I have two models (using a mysql backend), School and Student . The id field in School is a string, and contains 5-digit numbers assigned by the state, which include leading zeros. Student BelongsTo School , and contains a school_id field which is defined identically to the id field in School . I have done some testing, and I'm finding that when I