本文整理汇总了PHP中app\models\Category::first方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::first方法的具体用法?PHP Category::first怎么用?PHP Category::first使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Category
的用法示例。
在下文中一共展示了Category::first方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: it_can_delete_a_category
/**
* @test
* @return void
*/
public function it_can_delete_a_category()
{
DB::beginTransaction();
$this->logInUser();
$category = Category::first();
$response = $this->call('DELETE', '/api/categories/' . $category->id);
$this->assertEquals(204, $response->getStatusCode());
$response = $this->call('DELETE', '/api/categories/' . $category->id);
$this->assertEquals(404, $response->getStatusCode());
DB::rollBack();
}
示例2: search
public function search(Request $request)
{
if (!empty($request->input('category'))) {
$category = Category::findOrFail($request->input('category'));
} else {
$category = Category::first();
}
switch ($request->input('status')) {
case 1:
$words = $category->words()->userLearnedWords(auth()->user())->selectWords()->paginate(20);
break;
case 2:
$words = $category->words()->userUnlearnedWords(auth()->user())->selectWords()->paginate(20);
break;
default:
// Default is all words
$words = $category->words()->selectWords()->paginate(20);
break;
}
return view('words.home', ['words' => $words, 'categories' => $category->listCategories(), 'status' => $request->input('status'), 'category_id' => $category->id]);
}
示例3: function
<?php
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory->define(App\Models\User::class, function (Faker\Generator $faker) {
return ['name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt(str_random(10)), 'remember_token' => str_random(10)];
});
$factory->define(\App\Models\Category::class, function (\Faker\Generator $faker) {
$name = $faker->name;
return ['name' => $name, 'slug' => str_slug($name), 'type' => \App\Models\Category::TYPE_ARTICLE, 'status' => \App\Models\Category::STATUS_ACTIVE, 'introduction' => $name, 'parent_id' => 0];
});
$factory->define(\App\Models\Content::class, function (\Faker\Generator $faker) {
$content = join("\n\n", $faker->paragraphs(mt_rand(3, 6)));
return ['title' => $faker->sentence(mt_rand(3, 10)), 'slug' => $faker->name, 'type' => \App\Models\Content::TYPE_ARTICLE, 'category_id' => \App\Models\Category::first()['id'], 'content_raw' => $content, 'content_html' => $content, 'introduction' => str_limit($content), 'published_at' => $faker->dateTimeBetween('-10 days', '+3 days')];
});