我在laravel 4中将用户发送到用户消息系统.因此,在简化版本中,我必须使用表格
第一张桌子
用户
user_id | 用户名
第二张桌子
消息
message_id | message_from_user_id | message_to_user_id | message_content |
因此,在阅读文档后,我了解到用户有很多消息,消息属于User.
但是我如何在编码中实际关联它们呢?
我很困惑如何在这种情况下使用外键来获得一个有两个用户的消息?
我最近下载了一个版本的Laravel 4,它只有40kb.Laravel 3.2约为3.5mb,我的问题是:
谢谢.
有没有办法用Carbon制作一个简单的日历https://github.com/briannesbitt/Carbon?
我是新约会,并不确定如何去做.使用PHP日历类会更容易吗?我正在使用Laravel 4来实现这一目标,因此希望使用Carbon可以很容易地制作一个.
我最近在Laravel 4 Eloquent中了解了动态where子句(我认为这就是所谓的),它使得where子句User::where('first_name', 'Jon')->get()变得更好User::whereFirstName('Jon')->get().这有多灵活?
我可以举例如下
User::whereFirstNameOrLastName('Jon', 'Smith')->get();=像>=或LIKE我正在尝试为我的表单进行后端验证,但它不起作用.即使我提交了值,它也总是显示验证失败.
$validation = Validator::make(Input::all(), array(
array('email' => 'required'),
array('password' => 'required')
));
if ($validation->fails()) { // This is always failing
echo '<pre>';
print_r(Input::all());
die();
}
die('everything is OK!');
Run Code Online (Sandbox Code Playgroud)
Array
(
[_token] => ZnzZ2aDoTABIZZkvwxZoa7IjHkvK25ndibis5AbA
[email] => somedata
[password] => somemoredata
)
Run Code Online (Sandbox Code Playgroud)
你可以看到它甚至失败了,它清楚地表明了Input:all()这些值的设定.
我使用分页到bootstrap 3应用程序,并有一些错误.这就是我称之为分页的方式:
$newsletterUsers = NewsletterUser::paginate(2);
Run Code Online (Sandbox Code Playgroud)
然后在foreach循环后我把它:
{{ $newsletterUsers->links() }}
Run Code Online (Sandbox Code Playgroud)
没关系?但不是显示正常漂亮的laravel分页,而是数字一个在另一个上,没有样式,甚至没有正确分页,因为它用1 - 1 - 2个元素分页,而不是2 - 2,因为它应该是
这是html标记:
<div class="pagination">
<ul>
<li><a href="---/public/newsletterConfirmedUser?page=2">«</a></li>
<li><a href="---/public/newsletterConfirmedUser?page=1">1</a></li>
<li><a href="---/public/newsletterConfirmedUser?page=2">2</a></li>
<li class="active"><span>3</span></li><li class="disabled">
<span>»</span></li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
有人可以帮帮我吗?
错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: update `genre_books` set `provider_id` = ?, `genre_id` = ? where `id` is null) (Bindings: array ( 0 => 3, 1 => 466284, ))
Run Code Online (Sandbox Code Playgroud)
它正在成功添加一些数据,但在该表中,但在更新过程中仍会出现此错误.
模型:
class GenreBook extends Eloquent {
public $table = 'genre_books';
public $timestamps = false;
public $publicKey = 'book_id';
public function setRank($a) {
$this->sort_order = $a;
}
public function setProviderId($a) {
$this->provider_id = $a;
}
public function setBookId($a) {
$this->book_id = $a;
}
public …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用app/routes.php中的以下内容路由到RESTful控制器:
Route::controller('register', 'RegisterController');
Route::get('/', 'HomeController@showWelcome');
Run Code Online (Sandbox Code Playgroud)
在我的app/controllers/RegisterController.php文件中,我添加了以下内容:
<?php
class RegisterController extends BaseController
{
public function getRegister()
{
return View::make('registration');
}
public function postRegister()
{
$data = Input::all();
$rules = array(
'first_name' => array('alpha', 'min:3'),
'last_name' => array('alpha', 'min:3'),
'company_name' => array('alpha_num'),
'phone_number' => 'regex:[0-9()\-]'
);
$validator = Validator::make($data, $rules);
if ($validator->passes()) {
return 'Data was saved.';
}
return Redirect::to('register')->withErrors($validator);
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
当我在终端运行php artisan路线时,我得到:
+--------+--------------------------------------------------+------+----------------------------+----------------+---------------+
| Domain | URI | Name | Action | Before Filters | After Filters | …Run Code Online (Sandbox Code Playgroud) 我必须制作一个表格,其中我必须包括一个日历,用户可以在其中选择到达日期和外出日期.我怎么能用Laravel4做到这一点,并检索数据?非常感谢你!
我在Laravel 4中建立一个站点的管理员端,并且正在努力使一切都在雄辩中发挥作用.我正在尝试构建一个具有多个关系的对象.这似乎工作正常,直到我尝试加载次要关系.
这是我对YourDetail模型的调用:
$applicants = YourDetail::with(array('User', 'Application', 'SecondaryEds', 'SecondaryEds.SecondaryTypes', 'SecondaryEds.SecondaryGrades', 'FurtherEds', 'FurtherEds.FurtherTypes', 'FurtherEds.FurtherGrades', 'UniEds', 'UniEds.UniClassifications', 'UniEds.UniQualifications', 'WorkExperiences', 'WhyYou', 'StartDate', 'Referer'))->whereIn('user_id', $applicants);
Run Code Online (Sandbox Code Playgroud)
我的所有关系都在各种模型中定义,并且直接使用时工作正常.我遇到的问题是次要关系,例如
FurtherEds.FurtherTypes,FurtherEds.FurtherGrades,UniEds.UniClassifications,UniEds.UniQualifications,
等等
现在当我运行查询时,我得到了我所期望的 - 大约20个表示各种模型的选择查询,生成的选择查询带来了'FurtherEds.FurtherGrades'模型,例如如下所示:
select * from `further_grades` where `further_grades`.`deleted_at` is null and `further_grades`.`id` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好...
当我尝试通过集合对象访问这些模型时出现问题;
所以我要说我现在循环遍历我的集合,将每个对象传递给一个如下所示的视图:
foreach($applicants as $applicant){
View::make('ApplicantView', compact('applicant'));
}
Run Code Online (Sandbox Code Playgroud)
然后在我的视图中,我尝试遍历FurtherEds并回显出FurtherGrades模型的属性:
ApplicantView.blade.php
@foreach($applicant->FurtherEds as $fe)
{{ $fe->FurtherGrades->name }}
@endforeach
Run Code Online (Sandbox Code Playgroud)
这将为每个申请人创建一个新的SQL查询,尽管我尝试过急切加载,例如
select * from `further_grades` where `further_grades`.`deleted_at` is null and `further_grades`.`id` = …Run Code Online (Sandbox Code Playgroud) laravel-4 ×10
laravel ×9
php ×7
eloquent ×3
sql ×2
calendar ×1
controller ×1
forms ×1
laravel-3 ×1
pagination ×1
validation ×1
where-clause ×1