我尝试做的是:
我尝试将布尔值传递给我的视图以检查其是否正确。如果将其设置为true,我想添加一个类。我用Laravel。实际上,这是我的情况:
这是我的代码:
index.blade.php
@foreach($finances as $finance)
@if ($finance->depense = 1)
<tr class="red">
@elseif ($finance->depense = 0)
<tr>
@endif
<td><a href="{{ URL::to('finances/' . $finance->id) }}">{{$finance->description}}</a></td>
<td>{{ $finance->depense }}</td>
<td>{{ $finance->prix }}</td>
<td>{{ $finance->tps }}</td>
<td>{{ $finance->tvq }}</td>
<td>{{ $finance->grandtotal }}</td>
</tr>
@endforeach
Run Code Online (Sandbox Code Playgroud)
FinancesController.php
public function index()
{
$finances = Finance::all();
return View::make('finances.index')->withFinances($finances);
}
Run Code Online (Sandbox Code Playgroud)
怎么了?
我正在尝试找到一种不同的方法来保存/更新给定模型及其与数据库的关系.
基本上我有一个"作者"页面的表格,可以添加多个"书籍".当然,"作者"和"书"模型具有一对多的关系.
根据laravel官方教程,您必须:
Laravel还指出"有时您可能希望不仅保存模型,还保存其所有关系.为此,您可以使用push方法:$ user-> push();" .
但我找不到任何关于如何用"Book"关系填充"Author"模型的教程,实际上使用了push()方法
我正在寻找这样的东西:
$author = new Author();
$author->name = "Bill Jobs";
$author->phone = "555 - 123456";
// fill model with relations
$author->addRelation($relationsArray)
if($author->push())
{
// ....
}
Run Code Online (Sandbox Code Playgroud)
同样应该用于更新"作者":首先删除已存储的关系,而不是保存新关系
目前我正在重建一个现有的网站,旧网站是用CakePHP编写的,但新的网站是在Laravel.
旧用户必须能够使用与旧站点上使用的密码相同的密码登录,但这些密码在CakePHP中进行了哈希处理.
我的问题是:
有没有一种方法可以让我在Laravel中使用CakePHP密码哈希方式?
我试过寻找一个可以实现这一目标的包,但无济于事.
在Laravel,如果我有两条或更多条路线,比如:
Route::get('/{username}', 'UsersController');
Route::get('/{album}', 'AlbumsController');
Run Code Online (Sandbox Code Playgroud)
并且用户请求了一个页面www.example.com/foo,那么Laravel将如何确定用户是否选择了用户个人资料或专辑的页面.
我的Laravel应用程序出现此错误:
无法添加或更新子行:外键约束失败
这是我的2张桌子
用户
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('username');
$table->string('password');
$table->string('firstname');
$table->string('lastname');
$table->string('middlename');
$table->string('address');
$table->string('birthday');
$table->string('contact');
$table->string('email');
$table->enum('isAdmin', array(0,1))->default(0);
$table->enum('isTeacher', array(0,1))->default(0);
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
勤
Schema::create('attendance', function(Blueprint $table)
{
$table->increments('id');
$table->string('status');
$table->string('comment');
$table->integer('student_id')->unsigned();
$table->foreign('student_id')->references('id')->on('users');
$table->string('student_firstname');
$table->string('student_lastname');
$table->integer('teacher_id')->unsigned();
$table->foreign('teacher_id')->references('id')->on('users');
$table->string('teacher_firstname');
$table->string('teacher_lastname');
$table->timestamps();
Run Code Online (Sandbox Code Playgroud)
这是我的模特
用户
class User extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's …Run Code Online (Sandbox Code Playgroud) 以下是我的代码的一部分.但是当我运行该代码时,我收到错误"试图获取非对象的属性".
$searchdate = Input::get('curdate');
$teacherid = Auth::user()->id;
$student = WysStudent::where('studcls',$id)->get();
$clss = WysClass::where('clsteacher_id',$teacherid)->get();
$attendence_tbl = WysAttendancename::where('cls_id',$id)->first();
$wys_attendence_table = $attendence_tbl->attendance_name;
$attendance = DB::table($wys_attendence_table)->where('adate','=',$searchdate)->get();
if($attendance && $student){
foreach ($attendance as $attendance) {
foreach ($student as $student) {
var_dump($student->id);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
$attendance = DB::table($wys_attendence_table)->where('adate','=',$searchdate)->get();
Run Code Online (Sandbox Code Playgroud) 在我的控制器功能中,我使用一个require语句来包含一个文件:
require app_path().'/plivo/plivo.php';
Run Code Online (Sandbox Code Playgroud)
在此语句之后,我尝试使用以下语句从此控制器重定向:
return Redirect::back()->with('success', 'Note added successfully');
Run Code Online (Sandbox Code Playgroud)
但是,这给了我以下错误:
调用未定义的方法
Redirect::back()
如何从此功能重定向?
这是我的完整代码:
public function sendSMS(){
require app_path().'/plivo/plivo.php';
$auth_id = "XXXXXXXXXXXX";
$auth_token = "XXXXXXXXXXXXXXXXXXXXX";
$p = new \RestAPI($auth_id, $auth_token);
$params = array(
'src' => '1XX7XX0',
'dst' => '91XXXXXXXXX7',
'text' => 'Test SMS',
'method' => 'POST'
);
$response = $p->send_message($params);
return Redirect::back()->with('success', 'Note added successfully');
}
Run Code Online (Sandbox Code Playgroud) 路由参数不起作用,它是抛出和错误
throw new NotFoundHttpException;
Run Code Online (Sandbox Code Playgroud)
routes.php文件
Route::any('/share-to-group/(:any)/(:any)',array('as' => 'share-to-group',
'uses' => 'HomeController@shareToGroup'));
Run Code Online (Sandbox Code Playgroud)
视野内
<a href="{{ URL::to('share-to-group',[ $group['group_id'], $UnixDateTime ]) }}">Something</a>
Run Code Online (Sandbox Code Playgroud)
和控制器
function shareToGroup($group_id,$unixtime){
echo $group_id.$unixtime;exit;
}
Run Code Online (Sandbox Code Playgroud)
我在做什么?
我已经审查了以下链接,但这是完全不同的,这之间没有任何独特之处,我认为这不重复. 如何将查询字符串参数传递给Laravel4中的路由
我正试图在laravel发送邮件.不确定我是否正确地做了但我将所有内容都基于教程,并尽量保持简单.我究竟做错了什么?它目前给我一个错误:"传递给Illuminate\Mail\Mailer :: send()的参数2必须是数组类型,字符串" 如果我留下一个空的$ data,它表示它未定义.我不知道怎么做所有这些事情.有什么帮助吗?
$data = "helloooo";
Mail::send('emails.welcome', $data, function($message) {
$message->to('thatsmymail123@gmail.com', 'me')->subject('Welcome!'); });
Run Code Online (Sandbox Code Playgroud) 我正在尝试将此PHP MySQL查询构建到Laravel Query构建器:
$sql = "SELECT employee_name, employee_salary, employee_position, employee_city, employee_extension, DATE_FORMAT(employee_joining_date, '%Y-%m-%d') as employee_joining_date, employee_age ";
$sql .= " FROM employee WHERE 1=1";
if (!empty($EmployeeNameSeach) ) {
$sql .=" AND employee_name LIKE '".$EmployeeNameSeach."%' ";
}
if (!empty($SalarySeach)) {
$sql .= " AND employee_salary LIKE '".$SalarySeach."%' ";
}
if (!empty($PositionNameSeach) ) {
$sql .= " AND employee_position LIKE '".$PositionNameSeach."%' ";
}
if (!empty($CitySeach) ) {
$sql .= " AND employee_city LIKE '".$CitySeach."%' ";
}
if (!empty($ExtensionSeach) ) {
$sql .= …Run Code Online (Sandbox Code Playgroud)