laravel

Using Laravel pagination with Bootstrap-vue pagination

蓝咒 提交于 2021-02-11 13:47:57
问题 Is it possible to use Laravel pagination with Bootstrap-vue pagination ? I'm trying this: <b-pagination-nav :link-gen="linkGen"></b-pagination-nav> Default method of Bootstrap-vue: linkGen (pageNum) { return `${pageNum}` } But it doesn't seem possible to set first / prev / next / last pages links that Laravel sends me: current_page: (...) data: (...) first_page_url: (...) from: (...) last_page: (...) last_page_url: (...) next_page_url: (...) path: (...) per_page: (...) prev_page_url: (...) to

Unable to get and display grandchild relationship for dynamic menu in laravel 5.8

被刻印的时光 ゝ 提交于 2021-02-11 13:41:48
问题 I am creating dynamic multilevel menu in laravel, I am able to get parent and child relationship and display the menu but unable to get and display if relationship goes one more level down. Please assist. My Model: public function parent() { return $this->belongsTo('App\Menu', 'parent_id'); } public function children() { return $this->hasMany('App\Menu', 'parent_id'); } public function gchildren() { return $this->hasMany('App\Menu', 'parent_id'); } My Nav View: <ul class="navbar-nav">

Laravel | Polymorphic Relationship unknown column

早过忘川 提交于 2021-02-11 13:41:44
问题 This is my first time using a polymorphic relationship. I am creating a LMS where a Assignment can be allocated to a individual user or a team so reading the Laravel docs it seems that the Polymorphic Relationship will be a good way to go about it. I have created 4 tables. Users: | id | username | password | created_at | updated_at | Teams: | id | friendly_name | slug | Team User: | id | user_id | team_id | Assignment Allocation: | id | assignment_id | assignmentable_type | assignmentable_id

Conditional aggregation, filter in laravel

眉间皱痕 提交于 2021-02-11 13:23:57
问题 This is my second question based after the solution of Rows to columns based on date/time in Postgresql The table is in the upper link :) Here is my model: namespace App; use Illuminate\Database\Eloquent\Model; class StambMeasCanal extends Model { protected $connection = 'stamb'; protected $table = 'meas_kanal'; protected $fillable = ['fullname','formattedvalue','recordtime','qualitydesc','statedesc','id']; } Part of my controller: function getdata(Request $request) { $start_date = date('d-m

PHP textfile value to array

自作多情 提交于 2021-02-11 12:50:13
问题 I have $data variable like this: $data = [ 'name' => $name, 'student_id' => $student_id, ]; and I want to save it to text file: $path = storage_path('app/public/').'student.txt'; if (is_file($path)) { $path_ = Storage::disk('public')->prepend('data.txt', json_encode($data).','); } else { $path_ = Storage::disk('public')->put('data.txt', json_encode($data).','); } and then I want to see the output: $json = (Storage::disk('public')->get('data.txt')); return $json; and the value is: {"name":

How to Display a selected grade with its subject?

心已入冬 提交于 2021-02-11 12:42:35
问题 I want to when a user select a dropdown from the list, a group of subjects available for that grade must be displayed with checkboxes next to them My controller public function create() { $grades = Grade::with('subjects')->orderBy('slug', 'asc')->get(); return view('admin.users.create', compact( 'grades')); } Blade file <div class="form-group"> <select id="grade" name="grade" class="form-control @error('grade') is-invalid @enderror" v-model="selectedSubjects"> <option value="">Choose a Grade.

can be nullable and must be unique validation in laravel

余生颓废 提交于 2021-02-11 12:33:27
问题 $this->validate($request, [ 'id_num' => 'required | unique:users', //this should be nullable not required with unique. ]); Is it possible to nullable + unique at a time? then what will be the procedures? 回答1: Simply remove the required from the validator. Is it possible to nullable + unique at a time? Yes then what will be the procedures? You don't need a procedure, declare the field as unique in the table migration. $table->unique('id_num')->nullable(); then your validator must look like:

Is it possible to order by the total count of multiple tables?

牧云@^-^@ 提交于 2021-02-11 12:29:49
问题 I can't get this query to work! return Post::selectRaw('likes_count + comments_count as total_count') ->withCount(['likes', 'comments']) ->groupBy('posts.id') ->orderByDesc('total_count') ->paginate(); It works this way below but I want all the counts and something performant! return Post::leftJoin('likes', function ($join) { $join->on('posts.id', 'likes.likable_id') ->where('likes.likable_type', (new Post)->getMorphClass()); })->leftJoin('comments', function ($join) { $join->on('posts.id',

Laravel Excel Style with CSS not working while exporting view

ε祈祈猫儿з 提交于 2021-02-11 12:29:27
问题 I am trying to export view using laravel Excel 3.1. While the export is working, I am not being able to style it. My laravel Export looks as: <?php namespace App\Exports; use Illuminate\Contracts\View\View; use Maatwebsite\Excel\Concerns\FromView; use Maatwebsite\Excel\Concerns\WithEvents; use Maatwebsite\Excel\Concerns\RegistersEventListeners; use Maatwebsite\Excel\Events\AfterSheet; class MatrixExcelExport implements FromView, WithEvents { use RegistersEventListeners; protected $data,

Convert DATE_FORMAT to Y-m-d? Using Larave Eloquent Raw Select

徘徊边缘 提交于 2021-02-11 12:29:00
问题 Currently I have this eloquent select in laravel $queryBooking = Booking::where('id',$id)->select('starts_at','ends_at')->first(); Now I want to put specific format to starts_at and ends_at using this format Y-m-d Data should be shown somethings like this 2020-05-29 (Y-m-d) How can I do that using laravel eloquent? UPDATE tried the answer of spiny did some modification. $queryBooking = Booking::where('id',$id)->select('starts_at','ends_at')->first(); $booking = PropertyBooking::where(