我在laravel中有类别和子类别
namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
protected $table = 'categories';
public function parent()
{
return $this->belongsTo('App\Category', 'parent_id');
}
public function children()
{
return $this->hasMany('App\Category', 'parent_id');
}
}
Run Code Online (Sandbox Code Playgroud)
我可以添加属于已创建类别的新类别.像"测试 - >测试的子类别"之类的东西,然后让我说我将创建属于测试的子类别的"测试的子子类别",它将如下所示:"测试 - >测试的子类别 - >测试的子子类别"在视图中我想打印该类别的父母,如果有的话.我是这样做的:
@if($category->parent)
<td>{{ $category->parent->name }} <strong>-></strong> {{ $category->name }}</td>
@else
<td>{{ $category->name }}</td>
@endif
Run Code Online (Sandbox Code Playgroud)
但这仅显示一个父类别("测试的子类别 - >测试的子类别").我想展示所有看起来像这样的父母:"测试 - >测试的子类别 - >测试子类别"我怎么能这样做?
我想在laravel 5.4上传图片.这是代码:
if ($request->hasFile('image') && $request->image->isValid()) {
$image = $request->image;
$image_name = bcrypt($image->getClientOriginalName());
Storage::disk('public')->putFileAs('images', $image, $image_name . '.' . $image->getClientOriginalExtension());
$article->image($image_name);
}
Run Code Online (Sandbox Code Playgroud)
在FilesystemAdapter.php中(第146行)
我检查了FileSystemAdapter.php,看到问题出在这一行:
$stream = fopen($file->getRealPath(), 'r+');
Run Code Online (Sandbox Code Playgroud)
当我转储$ file变量时,它会返回正确的信息,但是当我var_dump($file->getRealPath();说它bool(false)并且我无法上传图像时
我有一个vue js组件,它向laravel路径发出axios请求.但是在vue文件中我无法访问该route()函数,现在必须使用静态url.这是一些代码:web.php:
// API
Route::group(['prefix' => 'api'], function() {
// GET
Route::get('/brands', 'BrandsController@getBrands')->name('api-get-brands');
Route::get('/{brand_id}/models', 'BrandsController@getModels')->name('api-get-models');
Route::get('/fuel-types', 'BrandsController@getFuelTypes')->name('api-get-fuel-types');
Route::get('/gearboxes', 'BrandsController@getGearboxes')->name('api-get-gearboxes');
});
Run Code Online (Sandbox Code Playgroud)
Vue组件:
methods: {
getBrands: function() {
let app = this
axios.get('/api/brands')
.then(function(response) {
app.brands = response.data
})
.catch(function(error) {
console.log(error)
})
},
...
Run Code Online (Sandbox Code Playgroud)
}
它现在有效,但我想知道这是最好的方式还是有更好的方法来做到这一点
我有以下请求验证:
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class OwnerEstate extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'firstname' => 'required_if:type,individual',
'secondname'=> 'required_if:type,individual',
'lastname' => 'required_if:type,individual',
'pin' => 'required_if:type,individual|digits:10',
'name' => 'required_if:type,legal-entity',
'eik' => 'required_if:type,legal-entity|digits:9'
];
}
}
Run Code Online (Sandbox Code Playgroud)
当类型不是个体时,它仍然会检查引脚的'digits:10'验证并返回错误.如果required_if验证不需要该字段,如何禁用其他验证. …
我已经尝试了键盘和更改功能,这就是为什么他们不做的伎俩.用户输入凭证代码,我想发送和ajax请求,检查数据库中是否存在凭证.我试过了:
$('#discount-voucher').keyup(function(event) {
// Get the value
let value = $(this).val()
// Check if exists
$.ajax({
url: '{{ route('get-voucher') }}',
type: 'POST',
data: {_token: '{{ csrf_token() }}', code: value}
})
.done(function(data) {
if (data == 'error') {
$('span#voucher-error').text('????????? ??????')
}
})
.fail(function() {
console.log("error")
})
.always(function() {
console.log("complete")
})
})
Run Code Online (Sandbox Code Playgroud)
但是这些优惠券将通过电子邮件发送,让我们说用户复制粘贴它们.不起作用.并且使用更改功能,用户必须在输入外部单击或按Enter键才能使功能生效,我不希望我也不想要一个提示/提示"点击输入外部或按输入检查"如果凭证有效".所以我需要的东西就像更改功能一样,无需点击或按回车即可生效
我有以下数组
// Exmaple
[
['morning', 'afternoon'],
['morning'],
['morning', 'afternoon'],
['morning', 'afternoon'],
['morning']
]
Run Code Online (Sandbox Code Playgroud)
我可能有相同的一个,但每个阵列都有下午.我需要检查,如果在所有的数组中存在一个给定的值,例如,如果我检查"早晨",它应该返回true,但如果我检查"午",它应该返回false的例子阵列,因为上面不是所有的人都有"下午"
laravel ×4
php ×3
javascript ×2
arrays ×1
jquery ×1
laravel-5 ×1
string ×1
validation ×1
vue.js ×1