我正在使用 Laravel 5.8 和 Slick.js 为我的在线商店显示幻灯片,我编写了以下代码:
Slick.prototype.initADA = function() {
var _ = this,
numDotGroups = Math.ceil(_.slideCount / _.options.slidesToShow),
tabControlIndexes = _.getNavigableIndexes().filter(function(val) {
return (val >= 0) && (val < _.slideCount);
});
_.$slides.add(_.$slideTrack.find('.slick-cloned')).attr({
'aria-hidden': 'true',
'tabindex': '-1'
}).find('a, input, button, select').attr({
'tabindex': '-1'
});
if (_.$dots !== null) {
_.$slides.not(_.$slideTrack.find('.slick-cloned')).each(function(i) {
var slideControlIndex = tabControlIndexes.indexOf(i);
$(this).attr({
'role': 'tabpanel',
'id': 'slick-slide' + _.instanceUid + i,
'tabindex': -1
});
if (slideControlIndex !== -1) {
var ariaButtonControl = 'slick-slide-control' + _.instanceUid + slideControlIndex …
Run Code Online (Sandbox Code Playgroud) 我有一条如下所示的路线。
Route::get('/articles/{articleSlug}' ,
[App\Http\Controllers\ArticleController::class, 'single']);
Run Code Online (Sandbox Code Playgroud)
single()
at类的方法ArticleController
如下:
public function single($slug)
{
$article = Article::where('slug',$slug)->first();
$article->increment('viewCount');
return view('home.article',compact('article'));
}
Run Code Online (Sandbox Code Playgroud)
现在我希望使用路由模型绑定根据articles
列从表中查找此数据slug
。但据我所知,路由模型绑定是根据id查找数据的。那么如何将路由模型绑定查找数据从仅更改id
为slug
仅用于ArticleController.php
(意味着其他控制器类可以使用 id 作为路由模型绑定)?
我有一个表,它有很多列,基本上,它table
的类table-responsive
带有以下 CSS 设置:
.table-responsive {
display: block;
width: 100%;
overflow-x: scrollbar;
}
Run Code Online (Sandbox Code Playgroud)
它正确显示水平滚动条:
但问题是,这个滚动条出现在表格的末尾,我希望它显示在显示数据的表格顶部(第一行的顶部)。
那么如何将水平滚动条移动到表格顶部(之后<thead>
)?
<table class="table table-bordered table-sm">
<thead class="thead-dark">
<tr>
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
..
<th>Col 10</th>
</tr>
</thead>
<tbody>
<tr>
...
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud) 我正在使用 Laravel 9,我有一个像这样的控制器:
use App\Repositories\HomeRepositoryInterface;
class HomeController extends Controller
{
private $homeRespository;
public function __construct(HomeRepositoryInterface $homeRepository)
{
$this->homeRespository = $homeRepository;
}
...
Run Code Online (Sandbox Code Playgroud)
这是HomeRepositoryInterface
:
<?php
namespace App\Repositories;
interface HomeRepositoryInterface
{
public function newest();
}
Run Code Online (Sandbox Code Playgroud)
这就是它HomeRepository
本身:
<?php
namespace App\Repositories;
use App\Models\Question;
class HomeRepository implements HomeRepositoryInterface
{
public function newest()
{
return $ques = Question::orderBy('created_at', 'DESC')->paginate(10);
}
}
Run Code Online (Sandbox Code Playgroud)
但现在我得到这个错误:
构建 [App\Http\Controllers\HomeController] 时,目标 [App\Repositories\HomeRepositoryInterface] 不可实例化。
那么这里出了什么问题呢?
我该如何解决这个问题?
我刚刚安装了 Laravel 8,在这个版本中,我必须像这样输入我的路线:
Route::get('/admin/panel', [App\Http\Controllers\Admin\PanelController::class, 'index']);
Run Code Online (Sandbox Code Playgroud)
但我习惯了 Laravel 5 的路线,如下所示:
Route::namespace('Admin')->prefix('admin')->group(function () {
Route::get('/panel', 'Admin/PanelController@index');
});
Run Code Online (Sandbox Code Playgroud)
那么如何在 Laravel 8 版本中使用 Laravel 5 路由呢?
我有一个 Laravel 9 论坛项目,对于Question
模型,我添加了以下内容:
public function user()
{
return $this->belongsTo(User::class);
}
Run Code Online (Sandbox Code Playgroud)
对于User
模型,我添加了以下内容:
public function questions()
{
return $this->hasMany(Question::class);
}
Run Code Online (Sandbox Code Playgroud)
基本上,每个问题都有一个名为的字段creator_id
,我想根据这个字段连接这两个模型之间的关系。
那么我该怎么做呢?
我正在使用 Laravel 和Spatie DNS Retriever从域名获取 IP 地址。
\n这是我的控制器方法:
\npublic function getDomainInfo($domain)\n {\n $dns = new Dns();\n $recordsA = $dns->getRecords($domain, [\'A\', \'CNAME\']);\n\n // dd($recordsA);\n\n $ip = $recordsA[0]->ip;\n dd($ip);\n\n return view(\'client.domain\', compact(\'records\',\'recordsA\',\'recordsMX\',\'recordsMX\',\'recordsAll\'));\n }\n
Run Code Online (Sandbox Code Playgroud)\n我收到此错误:
\n无法访问受保护的属性 Spatie\\Dns\\Records\\A::$ip
\n然而,结果将dd($recordsA)
其显示为输出:
array:1 [\xe2\x96\xbc // app/Http/Controllers/Client/IpInfoController.php:43\n 0 => Spatie\\Dns\\Records\\A {#294 \xe2\x96\xbc\n #host: "google.com"\n #ttl: 418\n #class: "IN"\n #type: "A"\n #ip: "216.239.38.120"\n }\n]\n
Run Code Online (Sandbox Code Playgroud)\n那么这里出了什么问题呢?这种情况下如何获取ip值呢?
\n我也尝试过这样获取 ip 值,但没有成功:
\ndd($recordsA[0][\'ip\']);
并返回此错误:
\n无法将 Spatie\\Dns\\Records\\A 类型的对象用作数组
\n我正在为我的 API 控制器使用此方法:
public function register(Request $request)
{
// Validation Data
$validData = $this->validate($request, [
'user_input' => 'required|regex:/^09\d{9}$/|max:11|min:11',
'user_full_name' => 'nullable|max:20|min:3',
]);
Session::put('user_full_name', $request->user_full_name);
$sms = new SendSms(request()->all()['user_input'],43,request()->all());
$sms->send();
return response([
'data' => 'verification code is sent',
'status' => 200
]);
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我在包含用户名的方法中设置了一个会话:
Session::put('user_full_name', $request->user_full_name);
Run Code Online (Sandbox Code Playgroud)
但这是错误的,因为我没有利用 REST API 的优势,并且 REST 不应该与会话一起提供。
而且我确实需要知道输入的用户名并获取后续步骤的数据,这就是我使用会话的原因。
所以问题是,在 REST API 中合适且标准的替代方法是什么?