我正在Windows环境中开发一个Laravel(5.2.29)项目并在Chrome浏览器上进行测试.
我使用原子文本编辑器对Blade文件进行了一些更改,然后刷新了我的页面并注意到它突然停止反映更改(它正在加载旧的Blade文件).
我尝试过以下方法:
php artisan cache:clearcomposer dumpautoload无论如何,浏览器上显示的代码始终是相同(旧)版本,而不是Blade文件的内容.
我该如何解决这个问题?
我创建了一个登记表,农民将输入他的名字.名称可能包含连字符或空格.验证规则写在app/http/requests/farmerRequest.php文件中:
public function rules()
{
return [
'name' => 'required|alpha',
'email' => 'email|unique:users,email',
'password' => 'required',
'phone' => 'required|numeric',
'address' => 'required|min:5',
];
}
Run Code Online (Sandbox Code Playgroud)
但问题是name由于alpha规则,该字段不允许任何空格.这个name领域是varchar(255) collation utf8_unicode_ci.
我该怎么做,以便用户可以用空格输入他的名字?
我对react-native和android完全陌生。我已经下载从GitHub项目和使用的命令yarn install,并react-native run-android运行该项目。但出现此错误。似乎无法理解原因。我该怎么办?
info Starting JS server...
info Installing the app...
> Task :app:validateSigningDebug FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings
17 actionable tasks: 17 executed
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:validateSigningDebug'.
> Keystore file '/home/tawsif/react native/react-native-redux/android/app/debug.keystore' not found for signing config 'debug'.
* Try:
Run with --stacktrace …Run Code Online (Sandbox Code Playgroud) 我是laravel的初学者.从来没有使用过框架.我创建了一个名为'tabletest'的数据库.它有两张桌子.一个是用户表,另一个是电话表.用户表有两列(id和name).电话表有3列(id phone和user_id).我正在尝试的是,我将使用表单输入并将输入发送到数据库表.尽管名称和电话已正确保存在不同的表中,但user_id(外键列)未更新.它总是0.我现在该怎么办?
迁移文件是:
用户表:
public function up()
{
Schema::create('user', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});
}
Run Code Online (Sandbox Code Playgroud)
电话表:
public function up()
{
Schema::create('phone', function (Blueprint $table) {
$table->increments('id');
$table->string('phone');
$table->unsignedInteger('user_id');
$table->timestamps();
});
}
Run Code Online (Sandbox Code Playgroud)
用户模型:
use App\Model\Phone;
class User extends Model
{
protected $table = "user";
protected $fillable = ['name'];
public function phone(){
return $this->hasOne(Phone::class);
}
}
Run Code Online (Sandbox Code Playgroud)
手机型号:
use App\Model\User;
class Phone extends Model
{
protected $table = "phone";
protected $fillable = ['phone','user_id'];
public function user(){
return $this->belongsTo(User::class);
}
} …Run Code Online (Sandbox Code Playgroud) mysql database foreign-key-relationship eloquent laravel-5.1
我很想知道,如果laravel eloquent在更新行时只运行一个查询.所以我尝试了以下内容
Route::get('/cli', function(){
DB::enableQueryLog();
$client = Client::findOrFail(1);
$client->first_name = 'Noob';
$client->save();
return response()->json([
'client' => $client->first_name,
'query' => DB::getQueryLog()
], 200);
});
Run Code Online (Sandbox Code Playgroud)
这给了我以下结果
{
"client": "Noob",
"query": [{
"query": "select * from `clients` where `clients`.`id` = ? limit 1",
"bindings": [
1
],
"time": 0.71
},
{
"query": "update `clients` set `first_name` = ?, `updated_at` = ? where `id` = ?",
"bindings": [
"Noob",
"2017-10-07 12:03:05",
1
],
"time": 3.36
}
]
}
Run Code Online (Sandbox Code Playgroud)
所以我想到了使用DB Facade.
Route::get('/cli', function(){
DB::enableQueryLog();
$client …Run Code Online (Sandbox Code Playgroud) 是否有任何方法/ laravel-command从生产服务器中删除特定的表?
我在我的项目中使用 vuejs 并注意到当页面处于加载状态时,我看到类似这样的东西{{ user.id }} {{ user.name }}非常烦人。
页面完全加载后,我可以正确地看到userId和user name。
如何在页面处于加载状态时停止在页面中显示 vuejs 的这些花括号?
几天前,我看到一个网站,用户可以在帖子上发表评论.其他用户可以回复此问题.并且重播可以有回复,如下面的示例屏幕截图..
所以我想试一试,但不知何故无法弄明白.这是我的数据库设置
Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('user_id');
$table->unsignedInteger('post_id');
$table->unsignedInteger('reply_id')->default(0);
$table->text('body');
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
模型中的关系
class Comment extends Model
{
protected $fillable = [
'user_id',
'post_id',
'reply_id',
'body'
];
public function user()
{
return $this->belongsTo(User::class);
}
public function post()
{
return $this->belongsTo(Post::class);
}
public function replies()
{
return $this->hasMany(Comment::class,'reply_id','id');
}
Run Code Online (Sandbox Code Playgroud)
在控制器中
$comments = Comment::with('replies')->where('reply_id','=',0)->get(['id','reply_id','body']);
return response($comments);
Run Code Online (Sandbox Code Playgroud)
这完美地回复了评论和回复.但如果有回复的回复,它就不会显示出来.我怎样才能做到这一点?需要建议.
即时尝试使用$ remove删除数组元素.但它说this.posts.$ remove不是一个函数.任何人都可以解释我错在哪里?
<button type="button" class="btn btn-danger" @click="deletePost(post.id)">Xxx</button>
Run Code Online (Sandbox Code Playgroud)
vue实例:
deletePost(postId){
console.log(postId);
this.posts.$remove(postId);
},
Run Code Online (Sandbox Code Playgroud)
这是我的示例数据
这是我的控制台
让我们考虑下图。我正在生成员工工作时间的月度报告。当水平滚动条向右移动时,我希望该code,name, area, territory列固定在其位置上,并且日期列应该可以水平滚动。向右滚动时,日期列应位于code,name, area, territory列组下方。我该怎么做?有没有可用的 CSS 技巧或插件?
我正在以下面的格式从后端接收对象数组.我试图获取这些数据并将其推送到JavaScript数组中,以便我可以根据我的需要在以后使用它们.
[
{
id: 1,
name: "Dr. Darrin Frami III",
email: "darrin67@example.com",
address: "42568 Cameron Cove Fritschborough, MA 86432-0749",
},
]
Run Code Online (Sandbox Code Playgroud)
这是我的vuejs代码:
<script>
export default {
data(){
return {
fakeUsers: [],
fakeUser: {id: '', name: '', email: ''},
}
},
methods:{
},
mounted() {
var route = '/get-users';
this.$http.get(route).then((response)=>{
for (var i = 0; i < response.data.length; i++) {
this.fakeUser.id = response.data[i].id;
this.fakeUser.name = response.data[i].name;
this.fakeUser.email = response.data[i].email;
this.fakeUsers.push(this.fakeUser);
}
});
console.log(this.fakeUsers);
console.log(this.fakeUsers[0]);
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
vue-dev工具结果:
线的输出 console.log(this.fakeUsers);是 …
假设我在users桌面上有250个用户,每个用户都有一本或多本书,每本书都有一个或多个章节.现在我想打印用户名和他们的书名.
控制器:
$users = User::all();
Run Code Online (Sandbox Code Playgroud)
在刀片中:
@foreach($users as $user)
<tr>
<td>{{ $user->id }}</td>
<td>{{ $user->name }}</td>
<td>
@foreach($user->books as $book)
{{ $book->name }},
@endforeach
</td>
</tr>
@endforeach
# of queries 252
Run Code Online (Sandbox Code Playgroud)
现在要克服n + 1问题,查询应该是
$users = User::with('books')->get();
Run Code Online (Sandbox Code Playgroud)
现在查询数量仅为2.
我想打印带有章节数的书名,如this-> BookName(章节数).所以在我的刀片中
@foreach($users as $user)
<tr>
<td>{{ $user->id }}</td>
<td>{{ $user->name }}</td>
<td>
@foreach($user->books as $book)
{{ $book->name }} ({{ $book->chapters->count() }}),
@endforeach
</td>
</tr>
@endforeach
Run Code Online (Sandbox Code Playgroud)
因此,对于包含1500章的750本书,查询数约为752,如果章节数增加则增加.
有没有更好的Eloquent方法来减少它或我应该去原始的SQL查询?
laravel ×6
javascript ×4
php ×4
eloquent ×3
mysql ×3
vue.js ×3
arrays ×2
laravel-5.1 ×2
vuejs2 ×2
blade ×1
css ×1
database ×1
forms ×1
html ×1
react-native ×1
validation ×1