我正在尝试从外部php脚本启动整个L5应用程序。我需要访问Eloquent模型和外墙。例如,我在单独的文件夹中有两个已安装和正在运行的应用程序:
我的nginx vhost配置:
0
my /var/www/drupal7/laravel/routes/web.php
location /laravel {
root /var/www/drupal7/laravel/public;
index index.php;
try_files $uri $uri/ /laravel/public/index.php?$query_string;
}
两个应用程序都运行良好,但我需要从外部脚本启动laravel应用程序,我希望能够访问模型,视图和配置。 我的问题是 - 我该怎么做呢?
我尝试使用以下代码实现此目的:
Route::get('/laravel', function () {
return 'Laravel';
});
但是我收到了以下错误消息:
<?php
require '/var/www/drupal7/laravel/bootstrap/autoload.php';
$app = new Illuminate\Foundation\Application(
'/var/www/drupal7/laravel/'
);
$app->singleton(
Illuminate\Contracts\Http\Kernel::class,
App\Http\Kernel::class
);
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
use App\User;
$user = User::find(1);
var_dump($user);
答案 0 :(得分:0)
尝试一下
var express = require('express');
var router = express.Router();
async = require('async');
var csrf = require('csurf');
var passport = require('passport');
var csrfProtection = csrf();
router.use(csrfProtection);
// Profile Routes
router.get('/profile',function(req,res,next){
res.render('user/profile');
});
// SIGN UP Routes
router.get('/signup',function(req,res,next){
var messages = req.flash('error');
// console.log("In Get Route "+ messages +" is the Error"); //req.flash not working.
res.render('user/signup', {csrfToken:req.csrfToken(), messages: messages , hasError: messages==undefined ?false :messages.length>0});
});
router.post('/signup',passport.authenticate('local-signup',{
successRedirect:'/user/profile',
faliureRedirect : '/user/signup',
// faliureMessage:'Not Valid',
faliureFlash:true,
// session:false
}));
//Sign In
router.get('/signin',function(req,res,next){
var messages = req.flash('error');
// console.log("In Get Route "+ messages +" is the Error"); //req.flash not working.
res.render('user/signin', {csrfToken:req.csrfToken(), messages: messages , hasError: messages==undefined ?false :messages.length>0});
});
router.post('/signin',passport.authenticate('local-login',{
successRedirect:'/user/profile',
faliureRedirect : '/user/signin',
faliureFlash:true,
// session:false,
}));
//Log Out
router.get('/logout',function(req,res,next){
req.logOut();
res.redirect('/');
});
module.exports = router;