laravel-5.1

Laravel custom validation message parameter

折月煮酒 提交于 2020-01-22 14:42:06
问题 I'm using laravel 5.1. I have a summernotejs form element. I've created a custom validation rule successfully, which takes the HTML provided from the form input, strips the tags, and does a strlen() call on the text content. Therefore I can see the length of a message without any tags in it. This is my validation rule: Validator::extend('strip_min', function ($attribute, $value, $parameters, $validator) { return strlen(strip_tags($value)) >= $parameters[0]; }); I call the validation rule by

How to access a property value inside JsonResponse Object in PHP or Laravel?

人盡茶涼 提交于 2020-01-21 07:33:06
问题 I'm doing a POST using Ajax and my Server is getting the data just fine. However, I'm struggling to access the value the user sent. In simple words how can I access the value of "user" (tom) ?. Anyone could get me on the right track please. Thank you in advance. Here's my JsonResponse object: [2016-10-22 05:10:49] local.INFO: From Ajax: Illuminate\Http\JsonResponse Object ( [data:protected] => {"user":"Tom","_token":"uRZJBVHH3worhjX4Ul6WlnJC1JYh3EVMNWob7Azr"} [callback:protected] =>

Laravel many to many relationship using Eloquent

泪湿孤枕 提交于 2020-01-20 05:19:04
问题 I'm trying to create a many to many relationship using Laravel, but I am stuck. Here's my current table model: album album_id name created_at user_image user_image_id value albumxuser_image (junction table) albumxuser_image_id (primary key & auto increment) album_id (FK from album) user_image_id (FK from user_image) I want to be able to get the album name from albumxuser_image table. Here's what I've done so far. Album.php model namespace App\Models; use Illuminate\Database\Eloquent\Model;

Redirecting User from Login Page to Home Page if Authenticated in Laravel

匆匆过客 提交于 2020-01-17 09:28:15
问题 I am building a login/register module using Laravel 5.1 I have defined the following routes Route::get('/', function () { return view('welcome'); }); Route::get('/home', ['middleware' => 'auth', function () { return view('home'); }]); I have also created a view for welcome and home. When I enter my credentials and login, I get redirected to the home page. How do I make sure that once I am authenticated and I try to access the '/' route, I get redirected to the home page. Currently once I am

Send Number Using HTML Form to Laravel

给你一囗甜甜゛ 提交于 2020-01-16 05:26:33
问题 I am curious on how laravel validates number, i had this code: $valid = \Validator::make(['lat' => '2.3711025426955', 'lng' => '99.0805054179688'], [ 'lat' => 'required_with:lng|digits_between:1,15', 'lng' => 'required_with:lat|digits_between:1,15', ]); dd($valid->fails()); which is invalid , it will work if we had the numbers without quotation marks. However, whatever input type of the input field to pass lat and long through html form. It regarded as string therefore invalid. I tried to dd(

Laravel Eloquent distinct values

为君一笑 提交于 2020-01-16 04:32:09
问题 PROBLEM SOLVED. I'm trying to get an person's books, but there are more than one book in my book table since there are different editions of a book. When I list all books of a person, I shouldn't list duplicates. Here's what I've done so far Person Model public function books() { return $this->belongsToMany('\App\Models\Thing', 'bookxauthor', 'person_id', 'thing_id'); } PersonController.php $allbooks = Person::find($id)->books; This is great, it lists all the books of an author, but I don't

In Laravel 5.1 Can't post value of checkbox

允我心安 提交于 2020-01-15 20:58:12
问题 I have 2 checkboxs inside a form, I can't post value of them. I have already tried this: <div class="form-group col-md-4"> <label class="col-md-6" for="invoiced"> <input type="checkbox" id="invoiced" value="false" name="project[invoiced]"> Invoiced </label> <label class="col-md-6" for="tobeinvoiced"> <input type="checkbox" id="tobeinvoiced" value="true" name="project[tobeinvoiced]" checked> To be Invoiced </label> </div> with this script that changes the value of 2 checkboxes in true or false

Replacing NULL value in current row based on 'closest' matching 'earlier' row. (date based table)

本小妞迷上赌 提交于 2020-01-15 08:17:27
问题 I have the following mysql table +---------------------+------+ | time | val | +---------------------+------+ | 2005-02-03 00:00:00 | 2.11 | | 2005-02-04 00:00:00 | 2.11 | | 2005-02-05 00:00:00 | NULL | | 2005-02-06 00:00:00 | NULL | | 2005-02-07 00:00:00 | 3.43 | | 2005-02-08 00:00:00 | NULL | | 2005-02-09 00:00:00 | NULL | | 2005-02-10 00:00:00 | 5.66 | | 2005-02-11 00:00:00 | 5.66 | | 2005-02-12 00:00:00 | NULL | +---------------------+------+ I want to create an algorithm (in PHP) that

Replacing NULL value in current row based on 'closest' matching 'earlier' row. (date based table)

∥☆過路亽.° 提交于 2020-01-15 08:17:24
问题 I have the following mysql table +---------------------+------+ | time | val | +---------------------+------+ | 2005-02-03 00:00:00 | 2.11 | | 2005-02-04 00:00:00 | 2.11 | | 2005-02-05 00:00:00 | NULL | | 2005-02-06 00:00:00 | NULL | | 2005-02-07 00:00:00 | 3.43 | | 2005-02-08 00:00:00 | NULL | | 2005-02-09 00:00:00 | NULL | | 2005-02-10 00:00:00 | 5.66 | | 2005-02-11 00:00:00 | 5.66 | | 2005-02-12 00:00:00 | NULL | +---------------------+------+ I want to create an algorithm (in PHP) that

Laravel-Many-to-one Polymorphic relationship

北战南征 提交于 2020-01-15 07:46:06
问题 I am using laravel 5.1. The scenario is as follows(this is an example. The real scenario is similar to this example) I have 3 models College Student Teacher A college can have many students but a student can belong to only 1 college. A college can have many teachers but a teacher can belong to only 1 college. I want to establish relationships between these tables in laravel. One of the methods for this is to place a college_id foreign key on the Students and Teachers table. But in my case,