laravel-5.2

Check if a class is a Model in Laravel 5

余生长醉 提交于 2019-12-07 12:27:14
问题 I have this code in Laravel 5.2 that checks if a given db table name ($what) has its own Model : public function manage($what) { $model = Str::studly(Str::singular($what)); if (!is_subclass_of($model, 'Model')) { \App::abort(404); } /* [... other stuff ...] */ } The problem is that is_subclass_of always fail, also when the model exist and it's a subclass of Model. I suppose it's a namespace problem, how can I fix it? 回答1: You may need the full namespace. When I do get_parent_class() on one of

Laravel Class mailer does not exist

感情迁移 提交于 2019-12-07 10:20:26
问题 I updated my application from 5 to 5.2. Now when I call Mail::send() it return an exception Class mailer does not exist. Mail::send('emails.mail', ['data' => $content], function ($m) use ($to, $subject,$toname) { $m->to($to, $toname)->subject($subject); }); When I open Illuminate\Support\Facades\Mail class there is only one function protected static function getFacadeAccessor() { return 'mailer'; } Please help. If anyone have any idea 回答1: Yes, I found the solution just put Illuminate\Mail

MySQL or PHP Transform rows to columns

巧了我就是萌 提交于 2019-12-07 09:55:30
I have this kind of table: the month are dynamically generated based on user input. The month can also be repeated. However, I want to transpose the month values to columns with a value of the amount but when trying it dynamically in mysql, it does not permit me because it can only return distinct values. I also tried removing distinct from my code below but it is not working. Any thoughts? CREATE DEFINER=`root`@`localhost` PROCEDURE `test`() BEGIN SET group_concat_max_len=2048; SET @sql = NULL; SELECT GROUP_CONCAT(DISTINCT CONCAT( 'MAX(IF(month = ''', month, ''', amount, NULL)) AS ', month )

Laravel - Integrity constraint violation: 1062 Duplicate entry

淺唱寂寞╮ 提交于 2019-12-07 08:09:16
问题 i have a problem when i try to create a new user in my database, if I add the users in phpmyadmin i have no problems, but when i try create users in my laravel web, the users has created with this error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '15.236.964-5' for key 'PRIMARY' I dont have idea which is the problem because in the database does not exist the same primary key. The table with problems is: CREATE TABLE IF NOT EXISTS `users` ( `rut` varchar(255) COLLATE

How to log every response in laravel 5.2 framework

ⅰ亾dé卋堺 提交于 2019-12-07 07:25:25
问题 I was using below code for logging each and every request and response for my API but now it's not working for Laravel 5.2. I have tried to use https://laravel.com/docs/5.2/middleware#terminable-middleware but not succeed. use Closure; use Illuminate\Contracts\Routing\TerminableMiddleware; use Illuminate\Support\Facades\Log; class LogAfterRequest implements TerminableMiddleware { public function handle($request, Closure $next) { return $next($request); } public function terminate($request,

How to use global prefix for tables in Laravel 5

戏子无情 提交于 2019-12-07 06:11:20
问题 New in Laravel. Probably a silly question. I had setup database like this: 'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', 'localhost'), 'port' => env('DB_PORT', '3306'), 'database' => 'mydb', 'username' => 'myusername', 'password' => 'mypassword', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => 'admin', 'strict' => false, 'engine' => null, ], Notice 'prefix' => 'admin' . This is because I want all tables related to the website's control panel be prefixed with

Validate a base64 decoded image in laravel

一世执手 提交于 2019-12-07 05:05:59
问题 Im trying to get a image from a PUT request for update a user picture(using postman), and make it pass through a validation in Laravel 5.2, for making the call in postman use the following url: http://localhost:8000/api/v1/users?_method=PUT and send the image string in the body, using a json like this: { "picture" : "data:image/png;base64,this-is-the-base64-encode-string" } In the controller try a lot of differents ways for decode the image and try to pass the validation: First I tried this:

Laravel 5.2 auth change 'users' table

六眼飞鱼酱① 提交于 2019-12-07 03:56:39
问题 I used the new feature in Laravel: php artisan make:auth But when I register it will use the database table users by default, but I want to change that to an other table. And by default it uses updated_at and created_at in that table, I want to remove that too. Auth/AuthController protected function create(array $data) { return User::create([ 'voornaam' => $data['voornaam'], 'email' => $data['email'], 'password' => bcrypt($data['password']), ]); } app\User protected $fillable = [ 'voornaam',

Class App\Http\Controllers\AuthController does not exist Laravel 5.2

杀马特。学长 韩版系。学妹 提交于 2019-12-07 01:57:02
问题 My whole application, made in Laravel 5.2, is working perfectly fine but when i tried to get list of routes through following command: php artisan route:list It shows me following error: [ReflectionException] Class App\Http\Controllers\AuthController does not exist i tried to add namespace aswell: Route::group(['middleware' => ['web'], 'namespace' => 'Auth'], function () { Route::auth(); }); then it shows me following error: [ReflectionException] Class App\Http\Controllers\Auth\Auth

How to add extra logic on login condition in Laravel 5.2

别来无恙 提交于 2019-12-07 01:29:06
问题 I just wanted to say if the user is not active, don't allow to login. I have made the controller as below, I am not sure what I am miising or what else I have to do here to make this work! namespace App\Http\Controllers\Auth; use Illuminate\Auth\Authenticatable; use Illuminate\Foundation\Auth\AuthenticatesUsers; use App\User; use Validator; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\ThrottlesLogins; use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; class