illuminate-container

Illuminate query builder, how to convert dates to Carbon object

喜你入骨 提交于 2021-01-29 11:53:37
问题 Is there any chance to use Illuminate Query builder to get dates as Carbon objects instead of strings? For example: $user=DB::table('users')->select(["id","lastLogin"])->where("id",1)->first(); $user->lastLogin; // <--- Carbon instead of string! 回答1: You can use Carbon::parse($user->lastLogin) , but I think there is no native way to get dates as carbon objects without using eloquent. An example is this answer on stackoverflow. I think working with eloquent models will make the work much

How can I add a join to a custom exists rule for a laravel validator?

∥☆過路亽.° 提交于 2020-06-22 12:27:30
问题 The validator in laravel can have a customization of the exists database rule, for instance if you need to check an extra column. An example from the manual: use Illuminate\Validation\Rule; Validator::make($data, [ 'email' => [ 'required', Rule::exists('staff')->where(function ($query) { $query->where('account_id', 1); }), ], ]); The query in the closure is not typehinted, so i'm not quite positive what kind of object this is. I can see that the DatabaseRule itself only has some function

Laravel's Illuminate paginator can't find query string

孤人 提交于 2020-03-03 11:32:14
问题 I'm working on a old PHP project, that is running in legacy SQL query, which is good but I like to use query builders like Laravel Illuminate SQL package! So i have added all required package dependencies to run Illuminate SQL, and this query builder seems to work fine with pagination! $users = Capsule::table('users')->paginate(1)->toArray(); But, the paginator seems not to be able to listen the query string! For example, by running the above code it would give some properties like, next_page

Laravel 6 config()->get('database.connections.mysql') not matching DB:connection()

旧城冷巷雨未停 提交于 2020-01-11 11:18:32
问题 Prerequisites In my local environment I am working with multiple tenants and Redis (Auth required). To serve the project I am using Valet. For this case I am addressing these two connections: - basic_foo (is defined in my .env) - tenant_foo (is the one to change to during a request) Until now I successfully changed the connections like so: config()->set('database.connections.mysql', array_merge( config()->get('database.connections.mysql') , ['database' => 'tenant_foo'] ); Problem However, now

How to create Illuminate/Support/Facade/App facade for standalone Illuminate IoC Container

只愿长相守 提交于 2020-01-02 03:51:08
问题 In my standalone (without Laravel) project i want to use Illuminate IoC container. Also i would like to access the app container through App facade provided by illuminate/support component. I installed both components (v5.0.28). Here is my (simplified) code: function setup_App(){ $container = new Illuminate\Container\Container(); Illuminate\Support\Facades\Facade::setFacadeApplication($container); class_alias('Illuminate\Support\Facades\App', 'App'); } setup_App(); App::bind('w', 'Widget');

Subclassing Migrator not working for namespaced migration

断了今生、忘了曾经 提交于 2019-12-14 02:38:50
问题 I have some namespaced migrations, and I can't get past the Class Not Found errors due to namespacing. In an earlier question, Antonio Carlos Ribeiro stated: Laravel migrator doesn't play nice with namespaced migrations. Your best bet in this case is to subclass and substitute the Migrator class, like Christopher Pitt explains in his blog post: https://medium.com/laravel-4/6e75f99cdb0. I have tried doing so (followed by composer dump-autoload , of course), but am continuing to receive Class

Illuminate library capsule object not accepting 'addConnection' command

随声附和 提交于 2019-12-12 04:06:43
问题 I am developing an application in Slim framework using Illuminate library. I am trying to create a connection to the database using Illuminate\Database\Capsule\Manager. Some how, it isnt recognizing the 'addConnection' statement. Here is my full code. If anyone can point out where I am going wrong, that would be very helpful. require 'lib/vendor/PHPMailer/PHPMailerAutoload.php'; require 'lib/init.php'; require 'lib/Slim/Slim.php'; date_default_timezone_set('UTC'); use lib\Slim\Middleware

How to embed a Laravel application within another web application?

不想你离开。 提交于 2019-12-11 09:37:01
问题 So I have a web application, say www.randomwebapp.com, and I want www.randomwebapp.com/laravelapp to point to a laravel app I have written. I've already figured out how to include my laravel app as a separate package and access classes within my laravel app, but I'm wondering how to actually go about rendering views/routing etc. I'm mainly concerned with how to actually start running the app (perhaps something to do with bootstrap/app.php or bootstrap/autoload.php). 回答1: I'm assuming you're

Multiple database connection using Illuminate/Database Eloquent ORM in CodeIgniter 3

百般思念 提交于 2019-12-10 18:15:59
问题 I have just included Laravel's database layer Eloquent to my CodeIgniter 3 project. My problem however is that I can't connect to multiple databases using Eloquent models. For the default DB, this is how I configured the DB: $capsule = new Capsule; $capsule->addConnection(array( 'driver' => 'mysql', 'host' => "localhost", 'database' => "employees_db", 'username' => "root", 'password' => "", 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', )); $capsule->setAsGlobal();

Illuminate Validator in stand-alone non-Laravel application

冷暖自知 提交于 2019-12-05 09:14:13
问题 I'm building an API using Slim and the Illuminate Database package with Eloquent models etc. I have instantiated the database handler using Capsule as shown in the README . However, now I want to use the validation features on my models without installing the full Laravel suite, but I cannot quite wrap my head around the design of this library. How would I go about this? It seems like the documentation provided for Laravel is pretty much expecting that you use Laravel out of the box. 回答1: