是否可以在laravel模型中使用继承?我解释:
是否可以执行一个扩展雄辩类的模型?
class A extends Eloquent
{
}
class B extends A
{
}
Run Code Online (Sandbox Code Playgroud)
e B也是2个不同的表,B有A_id作为外键和其他字段.怎么可能是B级的构造函数?它是一种可行的解决方案还是更好地使用hasOne关系?
没有每个A对象也是B对象.ES.用户和老师
谢谢
我正在尝试使用Laravel编写RESTful API.
我的路线是这样的:
Route::resource('user', 'UserController');
Run Code Online (Sandbox Code Playgroud)
方法是这样的:
public function show($id)
{
return User::findOrFail($id);
}
Run Code Online (Sandbox Code Playgroud)
但是如果模型实例不存在,我会得到500错误,而我相信我需要404错误.
所以在start/global.php中我有这个:
App::error(function(Illuminate\Database\Eloquent\ModelNotFoundException $exception)
{
App::abort(404);
});
Run Code Online (Sandbox Code Playgroud)
这给了我200个代码和异常处理程序中的错误消息.
难道我做错了什么?我希望没有输出和404代码.
谢谢,
迈克尔
尝试运行我的控制器时出现以下错误
未找到控制器类
我在我的routes.php文件中有这个代码
Route::get('cms/create-page', 'AdminCMSController@create_page');
Route::post('cms/createpage','AdminCMSController@createpage');
Route::controller('cms','AdminCMSController');
Run Code Online (Sandbox Code Playgroud)
这是我的控制器中的代码
class AdminCMSController extends BaseController {
public function create_page() {
}
public function createpage() {
}
}
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
我用laravel 4框架创建了一个工作用户/登录系统,一切运行良好.
但是我总是登录到站点,除非我运行注销过程.我想如果我登录,关闭所有浏览器窗口并再次打开浏览器我将被注销.不是这种情况.
在我的Auth :: attempt中,我将$ remember参数设置为false,即使它默认为false.
我不知道为什么会这样.如果我注销,关闭我所有的浏览器窗口然后再打开它我没有登录.所以这工作正常.但如果我已登录,请关闭所有浏览器,然后再次打开浏览器我已经登录.即使我已经指定记得是假的.
什么让我登录?为什么它总是记得我的登录?我找不到任何关于此的信息.
我在laravel 4项目中有两个.htaccess文件,一个在root中,另一个在公共文件夹中.我先复制了这一行:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
因为我不希望在域名之后输入/公共,并且它可以工作,但我复制了在第二个.htaccess中启用gzip的代码,它导致500内部服务器错误.我从gziptest.com/faq复制下面的行,我还尝试了很多其他文件,但没有一个适合我.
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/x-js
AddOutputFilterByType DEFLATE text/css
# Highest 9 - Lowest 1
DeflateCompressionLevel 9
# Skip browsers with known problems
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Run Code Online (Sandbox Code Playgroud)
请帮我?
似乎即使在添加Config params以启用YouTube和Vimeo Iframe之后,我仍然会收到异常错误."不支持元素'iframe'[..]"
return array(
'encoding' => 'UTF-8',
'finalize' => true,
'preload' => false,
'settings' => array(
'default' => array(
'HTML.Doctype' => 'XHTML 1.0 Strict',
'HTML.Allowed' => 'blockquote,div,b,strong,i,em,a[href|title],ul,ol,li,p[style],br,span[style],img[width|height|alt|src]',
'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align',
"HTML.SafeIframe" => 'true',
"URI.SafeIframeRegexp" => "%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/|api.soundcloud.com/tracks/)%",
'AutoFormat.AutoParagraph' => true,
'AutoFormat.RemoveEmpty' => true,
),
),
Run Code Online (Sandbox Code Playgroud) 为了更好地解释这个问题,我将举一个例子:
假设我有一个世界记录数据库,并希望为它创建一个api.假设我想添加一个接收search路径GET或POST参数(让我们保持简单,GET现在就说).是否有可能编写一个search控制器方法,它使用类似数组的东西作为Eloquent where方法的参数,同时还使用like参数(MySQL LIKE)?
我有以下工作,但仅适用于确切的值:
public function search()
{
$params = Input::all();
return Records::where($params)->get();
}
Run Code Online (Sandbox Code Playgroud) 我在laravel控制器中修剪用户输入的常用方法是这样的:
public function __construct()
{
if (isset($_POST)) $_POST = array_map('trim', $_POST);
if (isset($_GET)) $_GET = array_map('trim', $_GET);
}
Run Code Online (Sandbox Code Playgroud)
如何Input以类似的方式修剪laravel中的课程?
- 解决了 -
没关系,我发现Input::merge()了
如何在不发送电子邮件的情况下测试此代码段?
public function forgot()
{
$isValid = $this->updateForm->valid(Input::only('email'));
if ($isValid) {
$result = $this->user->forgot($this->updateForm->data());
if (isset($result['user']) && ($result['success'] > 0)) {
Event::fire('user.mail.forgot', array('data'=>$result['user']));
return Response::json(array('success'=>1),200);
}
$error = isset($result['error'])?array_pop($result):trans('user.generror');
return Response::json(array(
'success'=>0,
'errors' => array('error'=>array($error))),
200);
}
return Response::json(array(
'success' => 0,
'errors' => $this->updateForm->errors()),
200
);
}
Run Code Online (Sandbox Code Playgroud)
到现在我测试它:
public function _getSuccess($content)
{
$json = str_replace(")]}',\n", '', $content);
$native = json_decode($json);
return $native->success;
}
public function _set200($method, $uri, $parameters = array())
{
$this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
$response = $this->call($method, $uri, $parameters);
$this->assertResponseStatus(200); …Run Code Online (Sandbox Code Playgroud) 示例代码:
$user= user::orderBy('id')->first();
echo $user->created_at;
Run Code Online (Sandbox Code Playgroud)
上面的代码将返回类似的内容2014-07-25 22:41:19.我怎样才能只获得年,月或日?
谢谢.