Support the ongoing development of Laravel.io →
Configuration
Last updated 1 year ago.
0

Can you show us your code?

0

I used Eloquent outside L5 and fetched data from both MySQL, Mongo at the same time. Or even i successfully used Blade. I ended up needing almost all basic illuminate packages. I am going this way (outside L5) cause i am on a third party custom php framework and the job is to migrate gradually in L5 for several reasons. If there is a better approach by using a "normal" clean install of L5 in order to migrate gradually from the old deprecated custom framework i would love to hear about it.

Some code examples bellow : (these files are placed in a directory tree just like a normal installation of L5).

TestController.php

class TestController extends Controller {

	public function show()
    {
        $data = array(
            'name'  => 'Thanos',
            'age'   => 26
        );
        
        $users  = [1, 2];

        
        $blade = new Blade($GLOBALS['views_path'], $GLOBALS['cache_path']);
        echo $blade->view()->make( 'hello2', compact('data', 'users') );

    }
}
~~~~~~~~~

index.php
~~~~~~~~~
// Import Illuminate packages
require_once '../../../vendor/autoload.php';

// set database connection and setup
require_once '../../../config/bootstrap.php';

use Illuminate\Support\Facades\Response as Response;

// Instantiate the container
$app = new Illuminate\Container\Container();

// Tell facade about the application instance
Illuminate\Support\Facades\Facade::setFacadeApplication($app);

// register application instance with container
$app['app'] = $app;

// set environment 
$app['env'] = 'production';

$app->instance('request', \Illuminate\Http\Request::capture());
/*$app->singleton(
	'Illuminate\Contracts\Debug\ExceptionHandler',
	'App\Exceptions\Handler'
);
*/

// Register service providers

//with(new App\Providers\AppServiceProvider($app))->register();
with(new Illuminate\Events\EventServiceProvider($app))->register();
with(new Illuminate\Routing\RoutingServiceProvider($app))->register();
// with(new Illuminate\Routing\RoutingServiceProvider($app, new Illuminate\Http\Request()))->register();

with(new Illuminate\Auth\AuthServiceProvider($app))->register();
with(new Illuminate\Broadcasting\BroadcastServiceProvider($app))->register();
with(new Illuminate\Bus\BusServiceProvider($app))->register();
with(new Illuminate\Cache\CacheServiceProvider($app))->register();
// with(new Illuminate\Foundation\Providers\ConsoleSupportServiceProvider($app))->register();
with(new Illuminate\Routing\ControllerServiceProvider($app))->register();
with(new Illuminate\Cookie\CookieServiceProvider($app))->register();
with(new Illuminate\Database\DatabaseServiceProvider($app))->register();
with(new Illuminate\Encryption\EncryptionServiceProvider($app))->register();
with(new Illuminate\Filesystem\FilesystemServiceProvider($app))->register();
// with(new Illuminate\Foundation\Providers\FoundationServiceProvider($app))->register();
with(new Illuminate\Hashing\HashServiceProvider($app))->register();
with(new Illuminate\Mail\MailServiceProvider($app))->register();
with(new Illuminate\Pagination\PaginationServiceProvider($app))->register();
with(new Illuminate\Pipeline\PipelineServiceProvider($app))->register();
with(new Illuminate\Queue\QueueServiceProvider($app))->register();
with(new Illuminate\Redis\RedisServiceProvider($app))->register();
with(new Illuminate\Auth\Passwords\PasswordResetServiceProvider($app))->register();
with(new Illuminate\Session\SessionServiceProvider($app))->register();
with(new Illuminate\Translation\TranslationServiceProvider($app))->register();
with(new Illuminate\Validation\ValidationServiceProvider($app))->register();
with(new Illuminate\View\ViewServiceProvider($app))->register();

with(new Collective\Html\HtmlServiceProvider($app))->register();

// with(new ($app))->register();

// Class aliases
class_alias('Collective\Html\FormFacade', 'Form');
class_alias('Collective\Html\HtmlFacade', 'Html');

// Include all the routes
require '../../Http/files_routes.php';

// Instantiate the request
$request = Illuminate\Http\Request::createFromGlobals();

// Dispatch the router
$response = $app['router']->dispatch($request);

// Send the response
$response->send();
~~~~~~~~

bootstrap.php
~~~~~~~~

use Illuminate\Database\Capsule\Manager as Capsule;
use Jenssegers\Mongodb\Connection as Connection;

// Use the str_finish helper method to assure a trailing slash at the end of path string
$dirPath = str_finish(dirname(__DIR__), '/');

$GLOBALS['dir_path'] = $dirPath;

// Define globally the blade template paths
$GLOBALS['views_path'] = $dirPath . 'resources/views';
$GLOBALS['cache_path'] = $dirPath . 'resources/views/cache';

// Define globally controllers and models paths
$GLOBALS['controllers_path'] = $dirPath . 'app/Http/Controllers';
$GLOBALS['models_path'] = $dirPath . 'app/Models';

// Register Laravels autoloader
Illuminate\Support\ClassLoader::register();

// Register directories into the autoloader
Illuminate\Support\ClassLoader::addDirectories(array(
	$GLOBALS['controllers_path'],
	$GLOBALS['models_path']
));

// Include database credentials from config/database.php local file
$database_connections = require 'database.php';

/**
 * Configure the database and boot Eloquent
 */
$capsule = new Capsule;

$capsule->addConnection( $database_connections['mysql'] , 'mysql' );

$capsule->addConnection( $database_connections['mongodb'], 'mongodb' );

$capsule->getDatabaseManager()->extend('mongodb', function($config)
{
    return new Jenssegers\Mongodb\Connection($config);
});

Jenssegers\Mongodb\Model::setConnectionResolver($capsule->getDatabaseManager());

// Make this Capsule instance available globally via static methods
$capsule->setAsGlobal();

// Setup the Eloquent ORM
$capsule->bootEloquent();
// set timezone for timestamps etc

date_default_timezone_set('UTC');



hello2.blade.php

@extends('layouts.master')

@section('sidebar')
        

    <p>This is appended to the master sidebar.</p>
@stop

@section('content')
    
    {!! Form::open() !!}

	{!! Form::close() !!}

    
@stop
Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

galousis galousis Joined 8 Jul 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.