为何功能:
function wtf($dH)
{
switch ($dH)
{
case ($dH >= 0.0 && $dH < 1.0):
echo '$dH>=0';
break;
case ($dH >= 1.0 && $dH < 2.0):
echo '$dH>=1';
break;
case ($dH >= 2.0 && $dH < 3.0):
echo '$dH>=2';
break;
case ($dH >= 3.0 && $dH < 4.0):
echo '$dH>=3';
break;
case ($dH >= 4.4 && $dH < 5.0):
echo '$dH>=0';
break;
case ($dH >= 5.0 && $dH < 6.0):
echo '$dH>=5';
break;
default:
echo '$dH>=6';
break;
}
}
wtf(0.0); …Run Code Online (Sandbox Code Playgroud) 最近我开始使用laravel.但我想知道为什么它因为未定义的索引而崩溃并抛出异常.
例如:
$ ARR = []; 返回$ arr 1 ;
这导致应用程序崩溃并返回代码500.这一点都不好.我不需要它崩溃,它应该只返回null.
我怎么能处理这个?
其他建议用isset包装每一行,例如:
if(isset($arr[1]))
return $arr[1]
Run Code Online (Sandbox Code Playgroud)
我无法浏览所有代码并使用isset包装每一行.这是艰苦的工作.
谢谢
我在我的请求(Laravel请求验证)文件中使用以下代码
public function rules()
{
return [
'email'=>'required|email',
'password'=>'required'
];
}
public function messages()
{
return [
'email.required' => 'Please enter email ',
'email.email' => 'Please enter valid email ',
'password.required' => 'Enter your password.',
];
}
Run Code Online (Sandbox Code Playgroud)
如果登录凭据与用户表"错误的电子邮件/ ID或密码"不匹配,我想显示验证错误,是否可以在此处编写代码,或者我应该如何在控制器中编写代码.
提前致谢.
假设我有一个表结构表如下:
Table_A
sid (auto increment, primary)
.... some other column ....
created_at (created using laravel eloquent timestamps() function)
updated_at (same as above)
Run Code Online (Sandbox Code Playgroud)
然后,我创建了一个新列.
$new_row = new TableA; //TableA is a model created pointing to Table_A
$new_row->col1 = 'Some value';
$new_row->col2 = 'Some other value';
// Some other field
$new_row->save()
Run Code Online (Sandbox Code Playgroud)
然后,在这部分代码之后,
dd($new_row->sid);
Run Code Online (Sandbox Code Playgroud)
令人惊讶的是,输出是:
null
Run Code Online (Sandbox Code Playgroud)
但是,当我将其更改为:
dd($new_row->id);
Run Code Online (Sandbox Code Playgroud)
它返回sid(即行的主键值).当我在Laravel模型中使用自动增量作为主键时,主键的名称是否始终为id?或者为什么我在使用名称时只获得了价值id?
PS让我自己说清楚:我知道如何获得主键值,我知道我可以在模型中设置主键的名称.我想知道的是,这种行为是否适用于所有主键,或仅适用于具有主键的主键.
我有一个由表的位置$user->roles和列生成的集合。rolerole_namepermission
我想要的是获得一组权限并使用它,这样我就可以在需要数组的组件jquery中使用它。select2
<script>
$( document ).ready(function() {
$("#role_select").select2();
$('#role_select').val( {{ $user->roles->pluck('permission') }} ).trigger('change');
});
</script>
Run Code Online (Sandbox Code Playgroud)
上面的代码不起作用并在控制台中显示
["Super","Moderate"]
Run Code Online (Sandbox Code Playgroud)
那么我如何通过删除来获得一系列权限"?
[Symfony\Component\Debug\Exception\FatalErrorException] 语法错误,意外的 '(',需要标识符 (T_STRING) 或变量 (T_VARIABLE) 或 '{' 或 '$'
这是我的代码
public function up()
{
Schema::create('profile', function (Blueprint $table) {
$table->('userid')->unsigned()->default(0);
$table->string('profile')->default('http://localhost/laravel/public/image/uzair.jpg');
$table->string('about',255);
$table->foreign('userid')->references('id')->on('users')->onDelete('cascade');
$table->timestamps();
});
}
Run Code Online (Sandbox Code Playgroud) 我正在创建一个脚本来启动我的Laravel 5.8项目
#Install dependencies
composer self-update
composer install
# create .env base on .env.example
cat .env.example > .env
#permission
chmod -R 777 .env
#create the key
php artisan key:generate --force
cat .env
#set permission
chmod -R 777 bootstrap/ vendor/ storage/ public/
sleep 1
#clear cache
php artisan config:cache
php artisan cache:clear
composer dump-autoload
php artisan clear-compiled
php artisan key:generate
python -mwebbrowser http://127.0.0.1:8000
php artisan serve
Run Code Online (Sandbox Code Playgroud)
这条线似乎不起作用。
php artisan key:generate --force
Run Code Online (Sandbox Code Playgroud)
看看我的.env
?? bheng cat .env
APP_ENV=local
APP_URL=http://bheng.test/
APP_DEBUG=true
APP_KEY=***
CODE=### …Run Code Online (Sandbox Code Playgroud) 我有一个阵列
array:3 [?
1 => "2"
2 => "2"
3 => "0"
]
Run Code Online (Sandbox Code Playgroud)
我想计算值大于0的键的数量.在上面的例子中我应该得到答案2.
这是我的尝试.
return count($input_items > 0);
Run Code Online (Sandbox Code Playgroud)
这返回1
我想在javascript中使用route,但出现错误Route [product.like + productid] not defined.,有没有办法可以使用route呢?
阿贾克斯
$.ajax({
method: 'post',
url: '{{ route('product.like' productid) }}',
data: {
'user_id': userid,
'product_id': productid,
},
Run Code Online (Sandbox Code Playgroud)
路线
Route::post('product/like/{id}', ['as' => 'product.like', 'uses' => 'LikeController@likeProduct']);
Run Code Online (Sandbox Code Playgroud) laravel-5 ×9
laravel ×8
php ×6
eloquent ×2
ajax ×1
arrays ×1
artisan ×1
javascript ×1
jquery ×1
laravel-5.3 ×1
laravel-5.8 ×1
login ×1
model ×1