当前位置: 首页>>代码示例>>PHP>>正文


PHP Category::first方法代码示例

本文整理汇总了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();
 }
开发者ID:JennySwift,项目名称:lists,代码行数:15,代码来源:CategoriesTest.php

示例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]);
 }
开发者ID:jsnulla,项目名称:fels_rush,代码行数:21,代码来源:WordController.php

示例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')];
});
开发者ID:niefufeng,项目名称:drip,代码行数:23,代码来源:ModelFactory.php


注:本文中的app\models\Category::first方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。