laravel-5

Laravel 5.5 Collection where like

好久不见. 提交于 2021-02-05 11:13:24
问题 i am filtering data using collections. But i need to use like method. I had tried to write like this : ('name', 'LIKE', '%value%') but it did not work. Here is my method : protected function filterData(Collection $collection, $transformer) { foreach (request()->query() as $query => $value) { $attribute = $transformer::originalAttribute($query); if (isset($attribute, $value)) { $collection = $collection->where($attribute, $value); } } return $collection; } 回答1: The 1st question is whether you

Laravel Model Get Method Decoding JSON

ⅰ亾dé卋堺 提交于 2021-02-05 09:29:16
问题 Hi there below is what I'm storing in my db but when I use my get method in my model I have to use json_decode twice when formating my data why is this happening and can I have it just use it once somehow. json exactly in db: "[{\"id\":\"1\",\"country\":\"New Zealand\",\"shipping_rate\":\"1\"},{\"id\":\"2\",\"country\":\"Australia\",\"shipping_rate\":\"2\"}]" Model Get Method: public function getshippingAttribute() { return $this->attributes['shipping'] ? json_decode(json_decode($this-

php laravel preventing multiple logins of a user from different devices/browser tabs at a given time

半腔热情 提交于 2021-02-04 21:33:54
问题 Does laravel provide a way to prevent multiple logins of a user from different devices / browsers at a given time? If yes then how can i force a user to logged in from a single device at a single time. I am developing a online quiz app using laravel 5.6 where users can logged in from a single place and take test. 回答1: laravel provide this method to invalidating and "logging out" a user's sessions that are active on other devices logoutOtherDevices() to work with this method you need also to

php laravel preventing multiple logins of a user from different devices/browser tabs at a given time

六月ゝ 毕业季﹏ 提交于 2021-02-04 21:33:43
问题 Does laravel provide a way to prevent multiple logins of a user from different devices / browsers at a given time? If yes then how can i force a user to logged in from a single device at a single time. I am developing a online quiz app using laravel 5.6 where users can logged in from a single place and take test. 回答1: laravel provide this method to invalidating and "logging out" a user's sessions that are active on other devices logoutOtherDevices() to work with this method you need also to

Beginner in Laravel Delete data using modal

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-02 10:00:38
问题 My modal works so well and can delete data but not the exact id that i selected to delete like example id: 1, 2, 3, 4 and i will select id: 4 but the id: 4 will not delete the id deleted is id: 1 this is my delete function inside AllSystemController public function deletestorydata($id) { $story = Story::findOrFail($id); $story->delete(); return redirect()->back()->with('success', 'Data has successfully deleted.'); } and this is my route web.php in story section Route::get('stories/table',

Beginner in Laravel Delete data using modal

我的未来我决定 提交于 2021-02-02 10:00:01
问题 My modal works so well and can delete data but not the exact id that i selected to delete like example id: 1, 2, 3, 4 and i will select id: 4 but the id: 4 will not delete the id deleted is id: 1 this is my delete function inside AllSystemController public function deletestorydata($id) { $story = Story::findOrFail($id); $story->delete(); return redirect()->back()->with('success', 'Data has successfully deleted.'); } and this is my route web.php in story section Route::get('stories/table',

Beginner in Laravel Delete data using modal

你说的曾经没有我的故事 提交于 2021-02-02 09:58:28
问题 My modal works so well and can delete data but not the exact id that i selected to delete like example id: 1, 2, 3, 4 and i will select id: 4 but the id: 4 will not delete the id deleted is id: 1 this is my delete function inside AllSystemController public function deletestorydata($id) { $story = Story::findOrFail($id); $story->delete(); return redirect()->back()->with('success', 'Data has successfully deleted.'); } and this is my route web.php in story section Route::get('stories/table',

Laravel: Create HasMany Relationship Based On Condition

妖精的绣舞 提交于 2021-01-29 19:45:20
问题 I need to display reproductions based on Gender Condition Reproduction Table: $table->bigIncrements('id'); $table->unsignedInteger('father_id'); $table->unsignedInteger('mother_id'); ... I need to retrieve reproductions according to the gender User.php public function reproductions(){ if($this->gender == 'm'){ return $this->hasMany(Reproduction::class, 'father_id'); }else{ return $this->hasMany(Reproduction::class, 'mother_id'); } } Reproduction Table: id father_id mother_id 1 1 2 2 1 3 3 1 4

I am getting this error. Method Illuminate\Validation\Validator::validateReqiured does not exist

隐身守侯 提交于 2021-01-29 10:01:13
问题 I am getting this error for validation of form. Method Illuminate\Validation\Validator::validateReqiured does not exist. <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Event; use Illuminate\Support\Facades\Validator; use Illuminate\Validation\ValidationRequired; class EventController extends Controller { protected $events; public function __construct() { $this->property = new Event(); } /* get all data */ public function getEvents() { $events =Event::latest()-

Laravel hasone relationship

与世无争的帅哥 提交于 2021-01-29 09:16:20
问题 I am trying to use hasone relation but getting null error. below is my code User Model: function profile() { $this->hasOne('App\Profile'); } Profile Model: function User() { return $this->belongsTo('App\User'); } Register Controller protected function create(array $data) { $user = User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => Hash::make($data['password']), ]); if($user) { $profile = new Profile(); $profile->name = 'Fake Name'; $profile->father = 'Fake Father