基本上,我在我的数据库中有一个简单的'exp'列,我想使用一个函数'showLevel()',我可以将其Auth::user->username作为参数而不是静态名称传入.我正在努力解决如何在模板上使用echo或使用对象的函数.
public function index()
{
$users = User::all();
$level = $this->showLevel('test');
return view('home')->with('users', $users)->with('showLevel', $level);
}
public function showLevel($username) {
$level = DB::table('users')->where('username', $username)->pluck('exp');
if ($level < 500) {
return 1;
} else if ($level > 500 && $level < 1000) {
return 2;
} else if ($level > 1000 && $level < 1500) {
return 3;
} else if ($level > 1500 && $level < 2000) {
return 4;
} else if ($level > 2000 && $level …Run Code Online (Sandbox Code Playgroud) 我有一个Laravel应用程序设置,我正在使用Sentry 2进行用户身份验证.我有一个名为Post默认哨兵User表的模型.我想让一个用户有很多帖子,一个帖子属于一个用户.为了在我的数据库模式中反映这一点,我需要在posts和之间创建一个外键约束users.
我写的迁移如下:
public function up()
{
Schema::table('posts', function(Blueprint $table)
{
$table->integer('user_id')->after('id')->nullable();
$table->foreign('user_id')->references('id')->on('users');
});
}
Run Code Online (Sandbox Code Playgroud)
运行它后php artisan migrate,我在命令提示符中收到MySQL错误:
[Illuminate\Database\QueryException]
SQLSTATE [HY000]:常规错误:1005无法创建表'blog.dev.#sql-3bb_2d'(错误号:150)(SQL:alter tablepostsadd constraint posts_user_id_foreign foreign key(user_id)referencesusers(id))
起初我认为发生此错误是因为主键列的users定义与我的外键列不同user_id,但它们都定义为int(10).
从Google我了解到这个错误可能是由于两个列定义不同引起的,但是这里似乎并不是这样.
我必须对一个产品进行建模,该产品具有 Schema.orgProduct类型中未列出的属性。找了很多地方,都没有找到符合我需求的东西。如何扩展 Schema.orgProduct类型?
这个问题与这个问题相关:Uniform way to add multiple descriptive properties in Schema.org
最近,我在HTML5 & Schema.org - Structured Microdata for SEO上发现了这段代码,以及 Schema.orgWPHeader类型是WebPageElement可以包含CreativeWork以下Thing标记的声明:
<header role="banner" itemscope itemtype="http://schema.org/WPHeader">
<meta itemprop="name" content="A name">
<meta itemprop="description" content="A description text">
<h1 itemprop="headline">A headline text</h1>
<img itemprop="image" src="image.jpg">
</header>
Run Code Online (Sandbox Code Playgroud)
如果上面的陈述和用法WPHeader是正确的,我想知道下面的代码对于语义网的结构化数据是否有意义。我的问题背后的原因是,我正在寻找一种解决方案,在该解决方案中,我可以使用横幅/英雄图像来呈现具有典型属性(例如等Event)的(或其他)类型。CreativeWorkheadinecreator
<article>
<!-- Banner/hero image section for Event-->
<header class="my_hero_class" role="banner" itemscope itemtype="http://schema.org/WPHeader">
<meta itemprop="name" content="My Event">
<meta itemprop="description" content="Description of My …Run Code Online (Sandbox Code Playgroud) 我在应用程序中的某些对话框中使用了sweetalert2。但是,sweetalert2 网站提供了一些示例,当我将它们复制/粘贴到我的 Web 应用程序代码中时,这些示例报告了此错误:
SyntaxError: await is only valid in async functions and async generators
经过一些研究,我async之前添加了function testSweetalert(). 这虽然解决了语法错误,代码既没有达到陈述resolve('You need to select Ukraine :)')或swal('You selected: ' + country)。
下面的 Javascript 代码在我的 html 代码中是这样调用的:
<button onclick="testSweetalert()">test</button>
Run Code Online (Sandbox Code Playgroud)
<button onclick="testSweetalert()">test</button>
Run Code Online (Sandbox Code Playgroud)
尽管我试图了解有关async函数和使用的更多信息,但Promise我无法弄清楚上述代码有什么问题。这让我特别困惑,因为我在sweetalert2上找到的代码示例在他们的github页面上运行良好。
我需要将流明资源服务器中的文件内容(例如图像和其他mime类型)流式传输到Laravel客户端服务器。我知道在Laravel中我可以使用:
$headers = ['Content-Type' => 'image/png'];
$path = storage_path('/mnt/somestorage/example.png')
return response()->file($path, $headers);
Run Code Online (Sandbox Code Playgroud)
但是,file中没有该方法Laravel\Lumen\Http\ResponseFactory。
任何建议都非常欢迎。
laravel ×2
php ×2
schema.org ×2
asynchronous ×1
foreign-keys ×1
javascript ×1
laravel-5 ×1
lumen ×1
mysql ×1
php-7 ×1
semantic-web ×1
sweetalert2 ×1