我正在尝试在Laravel中创建外键但是当我使用artisan
i 迁移我的表时抛出以下错误:
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL
: alter table `priorities` add constraint priorities_user_id_foreign foreign
key (`user_id`) references `users` (`id`))
Run Code Online (Sandbox Code Playgroud)
我的迁移代码如下:
优先级迁移文件
public function up()
{
//
Schema::create('priorities', function($table) {
$table->increments('id', true);
$table->integer('user_id');
$table->foreign('user_id')->references('id')->on('users');
$table->string('priority_name');
$table->smallInteger('rank');
$table->text('class');
$table->timestamps('timecreated');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
Schema::drop('priorities');
}
Run Code Online (Sandbox Code Playgroud)
用户迁移文件
public function up()
{
//
Schema::table('users', function($table)
{
$table->create();
$table->increments('id');
$table->string('email');
$table->string('first_name');
$table->string('password');
$table->string('email_code'); …
Run Code Online (Sandbox Code Playgroud) 嗨,我最近下载了Laravel作为PHP框架,我已经安装了作曲家,并且已经有了它的工作,我已经根据Laravel网站创建了我的项目
composer create-project laravel/laravel --prefer-dist
Run Code Online (Sandbox Code Playgroud)
但是,当我使用上面的代码时,这会将我的项目安装在c:\ users\guti目录中,但是我希望它安装在c:\ xampp\htdocs中.
我在stackoverflow上看到了另一个问题,它讨论了修改composer.json文件,但我不确定这是否是我应该采取的路径,因为我已经对此文件进行了计算机搜索,并且该文件作为一部分存在laravel框架,所以修改这个文件是否有意义?
任何作曲家专家都能指出我正确的方向?
嗨,我正在尝试学习使用预准备语句的正确方法,以避免SQL注入等.
当我执行脚本时,我从我的脚本中得到一条消息,说0行已插入,我希望这可以说1行插入,当然更新表.我对我准备好的陈述并不完全确定,因为我做了一些研究,我的意思是它因例子而异.
当我更新我的表时,我需要声明所有字段还是只更新一个字段?
任何信息都会非常有用.
的index.php
<div id="status"></div>
<div id="maincontent">
<?php //get data from database.
require("classes/class.Scripts.inc");
$insert = new Scripts();
$insert->read();
$insert->update();?>
<form action="index2.php" enctype="multipart/form-data" method="post" name="update" id="update">
<textarea name="content" id="content" class="detail" spellcheck="true" placeholder="Insert article here"></textarea>
<input type="submit" id="update" name="update" value="update" />
</div>
Run Code Online (Sandbox Code Playgroud)
类/ class.Scripts.inc
public function update() {
if (isset($_POST['update'])) {
$stmt = $this->mysqli->prepare("UPDATE datadump SET content=? WHERE id=?");
$id = 1;
/* Bind our params */
$stmt->bind_param('is', $id, $content);
/* Set our params */
$content = isset($_POST['content']) ? $this->mysqli->real_escape_string($_POST['content']) …
Run Code Online (Sandbox Code Playgroud) 我正在使用Laravel 5.3
并且我正在尝试在方法中获取经过身份验证的用户id
,constructor
因此我可以按指定的公司过滤用户,如下所示:
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\View;
use App\Models\User;
use App\Models\Company;
use Illuminate\Support\Facades\Auth;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests ;
public $user;
public $company;
public function __construct()
{
$companies = Company::pluck('name', 'id');
$companies->prepend('Please select');
view()->share('companies', $companies);
$this->user = User::with('profile')->where('id', \Auth::id())->first();
if(isset($this->user->company_id)){
$this->company = Company::find($this->user->company_id);
if (!isset($this->company)) {
$this->company = new Company();
}
view()->share('company', $this->company);
view()->share('user', $this->user);
}
}
Run Code Online (Sandbox Code Playgroud)
但是这不会返回用户id …
我开始使用CakePHP为我的框架开发一个网站,我刚刚开始并且已经遇到过错误,我无法解决它们的含义.
Warning: _cake_core_ cache was unable to write 'cake_dev_en-us' to File cache in /Applications/XAMPP/xamppfiles/htdocs/evolvidsnew/lib/Cake/Cache/Cache.php on line 310
Warning: _cake_core_ cache was unable to write 'cake_dev_en-us' to File cache in /Applications/XAMPP/xamppfiles/htdocs/evolvidsnew/lib/Cake/Cache/Cache.php on line 310
Warning: /Applications/XAMPP/xamppfiles/htdocs/evolvidsnew/app/tmp/cache/persistent/ is not writable in /Applications/XAMPP/xamppfiles/htdocs/evolvidsnew/lib/Cake/Cache/Engine/FileEngine.php on line 320
Warning: /Applications/XAMPP/xamppfiles/htdocs/evolvidsnew/app/tmp/cache/models/ is not writable in /Applications/XAMPP/xamppfiles/htdocs/evolvidsnew/lib/Cake/Cache/Engine/FileEngine.php on line 320
Warning: /Applications/XAMPP/xamppfiles/htdocs/evolvidsnew/app/tmp/cache/ is not writable in /Applications/XAMPP/xamppfiles/htdocs/evolvidsnew/lib/Cake/Cache/Engine/FileEngine.php on line 320
Run Code Online (Sandbox Code Playgroud)
我也收到有关以下内容的错误:
Notice (1024): Please change the value of 'Security.salt' in app/Config/core.php to a salt value specific to …
Run Code Online (Sandbox Code Playgroud) 我想clients
在项目控制器中使用我的数据库填充选择框,因为项目将属于a client
但它也属于登录的用户.
我想创建一个如下所示的选择框:
<select>
<option value="$client->client_id">$client->client_name</option>
<option value="$client->client_id">$client->client_name</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我在laravel中使用客户端名称填充我的选择字段但是该value
属性具有客户端名称,我宁愿这有client_id.
我这样做的方式如下:
ProjectController.php
public function create()
{
//find logged in users clients
$clients = Auth::user()->clients;
$client_selector = array();
foreach($clients as $client) {
$client_selector[$client->client_name] = $client->client_name;
}
// load the create form (app/views/projects/create.blade.php)
return View::make('projects.create', array('client_selector' => $client_selector));
}
Run Code Online (Sandbox Code Playgroud)
create.blade.php
{{ Form::open(array('action' => 'ProjectController@store', 'id' => 'createproject')) }}
<div class="form-group">
@if(count($client_selector)>0)
{{ Form::label('select_client', 'Select Client', array('class' => 'awesome')); }}
<!-- SELECT IS CREATED HERE -->
{{Form::select('client', $client_selector, …
Run Code Online (Sandbox Code Playgroud) 嗨,我想要检索我projects
所拥有的数据库,这些数据库由auth拥有,user
他也创建clients
(他们有许多项目和任务)和tasks
(属于项目,任务和用户).
我想检索状态表中未标记为已关闭的所有任务,我知道这个ID是2,我可以这样检索:
public function getOpenProjects() {
return \Project::with(['clients', 'tasks', 'status'])
->where('status_id', '!=', '2')
->whereUserId(Auth::user()->id)
->get();
}
Run Code Online (Sandbox Code Playgroud)
但是如何更改此选项以查询状态表中的列,即该表中的名称列?
嗨我正在使用以下软件包https://github.com/jayhealey/Robots为我的应用程序中的每个环境添加不同的robots.txt文件.然而,这是我在我的应用程序上使用的一种方法,即爬行延迟,即
Crawl-delay: 3600
现在我从这个包的composer安装中得到以下文件夹:
vendor/healey/robots/src/Healey/Robots/Robots.php,这样开始:
<?php namespace Healey\Robots;
class Robots
{....}
Run Code Online (Sandbox Code Playgroud)
现在我希望能够扩展这个类,这样我就可以成功地使用它中的方法,但显然不希望在vendor目录中添加该函数,因为这是不可取的.所以我创建了以下类:
应用程序/ LIB /助手/ AppRobots.php
这有以下内容:
<?php
use Healey\Robots\Robots;
class AppRobots extends Robots {
/**
* Add crawl Delay to robots.txt.
*
* @param string $delay
*/
public function crawlDelay($delay)
{
$this->addLine("Crawl-delay: $delay");
}
}
Run Code Online (Sandbox Code Playgroud)
现在在routes.php我有以下内容:
Route::get('robots.txt', function() {
// If on the live server, serve a nice, welcoming robots.txt.
if (App::environment() == 'production')
{
\Robots::addUserAgent('*');
\AppRobots::crawlDelay('3600');
} else {
// If you're on any other server, …
Run Code Online (Sandbox Code Playgroud) 我正在创建自己的HTML 5浏览器播放器.所有控件分开工作,使得在IE 10,Chrome,Safari和Firefox中全屏工作非常好.
我的JavaScript技能并不是最好的,所以如果有人能够以一种简单的方式为我解释事情就会很棒.
我在一些网站上看到IE不支持全屏,如果是这样的话,为什么我可以通过IE10上的浏览器播放器控件进入全屏?(讨厌微软如此垃圾,一切都在后面!)
将不胜感激,帮助和建议!提前致谢!
这是我到目前为止的全屏功能:
function toggleFullScreen() {
if(vid.requestFullScreen) {
vid.requestFullScreen();
} else if(vid.webkitRequestFullScreen) {
vid.webkitRequestFullScreen();
} else if(vid.mozRequestFullScreen) {
vid.mozRequestFullScreen();
}
}
Run Code Online (Sandbox Code Playgroud) 我想在我的数据库模式下面的客户端表中插入一个日期,我想将它们插入到start_day
和end_day
字段中.
我在ClientController.php中的验证中有以下内容
如果我插入一个date_format
不同于下面定义的异物,我会抛出一个错误,但是如果我插入了正确的异常,它将恢复为0000-00-00
.但是,如果我改变字段type
到text
例如date_format
插入罚款.
$rules = array(
'project_name' => 'required',
'project_brief' => 'required',
'start_day' => array('required', 'date_format:"m-d-Y"'),
'end_day' => array('required', 'date_format:"m-d-Y"')
);
Run Code Online (Sandbox Code Playgroud)
老实说,我不确定问题在哪里.我甚至试图将时间转换成以下内容:
$start_day_old = Input::get('start_day');
$start_day = date("d-m-Y", strtotime($start_day_old));
$project = new Project;
$project->start_day = $start_day
$project->save();
Run Code Online (Sandbox Code Playgroud)
但结果是一样的.有谁知道如何纠正这个问题?
php ×6
laravel ×4
laravel-4 ×4
eloquent ×2
cakephp ×1
cakephp-2.0 ×1
composer-php ×1
extend ×1
foreign-keys ×1
fullscreen ×1
html5-video ×1
installation ×1
javascript ×1
laravel-5.3 ×1
migration ×1
mysqli ×1
select ×1
sql-update ×1