/** * Store a newly created resource in storage. * * @return Response */ public function store(TagRequest $request) { $tag = new \App\Tag($request->all()); $tag->save(); \Session::flash('create_new_tag', 'Your tag has been created.'); return redirect('admin/tag'); }
public function store(Request $request) { $this->validate($request, ['name' => 'required|unique:tags,name']); $tag = new \App\Tag(); $tag->name = strtolower($request->input('name')); $tag->save(); return redirect('backend/tags' . $tag->id); }
/** * Create fake tag * * @return \App\Tag */ private function createFakeTag() { $faker = Faker\Factory::create(); $tag = new \App\Tag(); $tag->title = $faker->word; $tag->save(); return $tag; }
/** * Store a newly created resource in storage. * Tags have user_id and name * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $tag = new \App\Tag(); $tag->user_id = Auth::user()->id; $tag->name = $request->name; $tag->save(); return $tag; }
/** * Run the database seeds. * * @return void */ public function run() { $data = ['Hybrid', 'Fuel Cell', 'Sedan', 'Mini Van', 'SUV', 'Wagon', 'Truck', 'Hatchback', 'Coupe', 'Premium', 'Luxury', 'Convertible', 'Specialty Car']; foreach ($data as $tagName) { $tag = new \App\Tag(); $tag->name = $tagName; $tag->save(); } }
/** * Run the database seeds. * * @return void */ public function run() { $data = ['mysql', 'security', 'php', 'model', 'view', 'controller', 'nonfiction', 'ui', 'css', 'js', 'html']; foreach ($data as $tagName) { $tag = new \App\Tag(); $tag->name = $tagName; $tag->save(); } }
/** * Run the database seeds. * * @return void */ public function run() { $tags = ['Bangkok', 'Bilbao', 'Buddhism', 'Camino del Norte', 'Camino Inglès', 'Chenab Valley', 'Chiang Mai', 'climbing', 'cycling', 'Delhi', 'gold', 'Himachal Pradesh', 'holy man', 'Jammu & Kashmir', 'Indian Railways', 'Kangra Valley', 'Keylong', 'Khardung', 'Khardung La', 'Kunzum La', 'Ladakh', 'Leh', 'monastery', 'mural', 'narrow-gauge', 'Nubra Valley', 'Orissa', 'Panji Valley', 'pedal-powered', 'portrait', 'prayer flags', 'prayer wheel', 'Sinthan Top', 'Spiti', 'Srinagar', 'Stanage', 'Tamil Nadu', 'trohloff', 'West Bengal']; foreach ($tags as $tagName) { $tag = new \App\Tag(); $tag->name = $tagName; $tag->save(); } }
/** * Run the database seeds. * * @return void */ public function run() { $data = ['novel', 'fiction', 'classic', 'wealth', 'women', 'autobiography', 'nonfiction']; foreach ($data as $tagName) { $tag = new \App\Tag(); $tag->name = $tagName; $tag->save(); } }
/** * Responds to requests to GET /books/create */ public function getCreate() { $formatModel = new \App\Format(); $formats_for_dropdown = $formatModel->getFormatsForDropdown(); # Get all the possible tags so we can include them with checkboxes in the view $tagModel = new \App\Tag(); $tags_for_checkbox = $tagModel->getTagsForCheckboxes(); return view('books.create')->with('formats_for_dropdown', $formats_for_dropdown)->with('tags_for_checkbox', $tags_for_checkbox); }
/** * Run the database seeds. * * @return void */ public function run() { $data = ['php', 'mysql', 'js', 'html', 'forms', 'front-end', 'css']; foreach ($data as $tagName) { $tag = new \App\Tag(); $tag->name = $tagName; $tag->save(); } }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // $tag = new \App\Tag(); $tag->user_id = Auth::user()->id; $tag->name = $request->name; $tag->save(); return $tag; }
/** * Show a page to create a new image * @return \Response */ public function getCreate() { // get list of countries $countryModel = new \App\Country(); $countries_for_dropdown = $countryModel->getCountriesForDropdown(); // get list of tags $tagModel = new \App\Tag(); $tags_for_dropdown = $tagModel->getTagsForDropdown(); return view('images.create')->with('countries_for_dropdown', $countries_for_dropdown)->with('tags_for_dropdown', $tags_for_dropdown); }
public function saving($model) { $tag_model = new \App\Tag(); // RULES if (is_array($model->tag_ids)) { foreach ($model->tag_ids as $k => $v) { $rules['tag_ids' . $k] = ['exists:' . $tag_model->getTable()]; } } else { $rules['tag_ids'] = ['exists:' . $tag_model->getTable()]; } $validator = Validator::make($model->toArray(), $rules); if ($validator->fails()) { $model->setErrors($validator->messages()); return false; } }
public function run() { DB::table('users')->delete(); $user = App\User::create(['name' => 'admin', 'email' => '*****@*****.**', 'created_at' => Carbon\Carbon::now(), 'updated_at' => Carbon\Carbon::now(), 'password' => bcrypt('r2g9R8hJBXazT23g')]); Auth::attempt(['email' => '*****@*****.**', 'password' => 'password']); App\Tree::create(['title' => 'new tree', 'description' => 'TinyDescription', 'user_id' => $user->id, 'updated_by' => $user->id, 'locked' => 0]); App\Tree::create(['title' => 'new tree2', 'description' => 'TinyDescription 2', 'user_id' => $user->id, 'updated_by' => $user->id, 'locked' => 0]); App\Tag::create(['title' => 'social engineering', 'slug' => 'social_engineering', 'color' => '#FF0000']); $user2 = App\User::create(['name' => 'John Doe', 'email' => '*****@*****.**', 'created_at' => Carbon\Carbon::now(), 'updated_at' => Carbon\Carbon::now(), 'password' => bcrypt('password')]); Auth::attempt(['email' => '*****@*****.**', 'password' => 'password']); App\Tree::create(['title' => 'new tree3', 'description' => 'TinyDescription 2', 'user_id' => $user2->id, 'updated_by' => $user2->id, 'locked' => 0]); }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker\Factory::create(); $limit = 40; for ($i = 0; $i < $limit; $i++) { $tag = DB::table('tags')->insert(['value' => $faker->text($maxNbChars = 10)]); } $stories = App\Story::get(); foreach ($stories as $story) { $tag_id = rand(1, count(App\Tag::get())); DB::table('story_tag')->insert(['story_id' => $story->id, 'tag_id' => $tag_id]); } }
/** * Run the database seeds. * * @return void */ public function run() { //factory(PostHasTag::class, 50)->create(); $posts = App\Post::all(); $tags = App\Tag::all(); foreach ($posts as $post) { $list = []; foreach ($tags as $tag) { rand(0, 5) == 0 && count($list) < 10 ? $list[] = $tag->id : null; } $post->tags()->sync($list); } }
/** * Responds to requests to GET /books/edit/{$id} */ public function getEdit($id = null) { // get book to edit $book = \App\Book::with('tags')->find($id); $authorModel = new \App\Author(); $authors_for_dropdown = $authorModel->getAuthorsForDropdown(); // get all the tags $tagModel = new \App\Tag(); $tags_for_checkboxes = $tagModel->getTagsForCheckboxes(); //dump($tags_for_checkboxes); // get the tags for this book $tags_for_this_book = []; foreach ($book->tags as $tag) { $tags_for_this_book[] = $tag->name; } //dump($tags_for_this_book); //dump($authors_for_dropdown); if (is_null($book)) { \Session::flash('flash_message', 'Book not found.'); //return redirect('\books'); } return view('books.edit')->with(['book' => $book, 'authors_for_dropdown' => $authors_for_dropdown, 'tags_for_checkboxes' => $tags_for_checkboxes, 'tags_for_this_book' => $tags_for_this_book]); }
/** * Run the database seeds. * * @return void */ public function run() { factory(App\Product::class, 15)->create()->each(function ($product) { $allTags = App\Tag::all(); $tags = $allTags; $nbProductTags = rand(1, $allTags->count()); while ($nbProductTags != 0) { $indiceTags = rand(1, $tags->count()) - 1; DB::table('product_tag')->insert([['product_id' => $product->id, 'tag_id' => $tags[$indiceTags]->id]]); // $Product->tags()->attach([$tags[$indiceTags]->id]); // voir la solution du prof $tags->splice($indiceTags, 1); //suppression de l'élément dans la collection $tags $nbProductTags--; } }); }
/** * Run the database seeds. * * @return void */ public function run() { // $faker = Faker\Factory::create(); $limit = 20; for ($i = 0; $i < $limit; $i++) { echo $faker->city; for ($i = 0; $i < $limit; $i++) { DB::table('tags')->insert(['value' => $faker->word]); } } $stories = App\Story::get(); foreach ($stories as $story) { $tag_id = $tag_id = rand(1, count(App\Tag::get())); DB::table('story_tag')->insert(['story_id' => $story->id, 'tag_id' => $tag_id]); } }
/** * Run the migrations. * * @return void */ public function up() { Schema::create('lv_posts', function (Blueprint $table) { $table->increments('id'); $table->timestamps(); $table->string('title'); $table->text('body'); }); $tags = App\Tag::all(); factory(App\Post::class, 3)->create()->each(function ($p) use($tags) { for ($i = 0; $i < 3; $i++) { $p->comments()->save(factory(App\Comment::class)->make()); } foreach ($tags as $t) { $p->tags()->attach($t['id']); } }); }
/** * Run the database seeds. * * @return void */ public function run() { $positions = ['Banja Luka' => ['lat' => '44.7785709', 'lng' => '17.1361267'], 'Gradiska' => ['lat' => '45.1413827', 'lng' => '17.2405045'], 'Srbac' => ['lat' => '45.0965046', 'lng' => '17.5078242'], 'Mrkonjic Grad' => ['lat' => '44.4149267', 'lng' => '17.0813563'], 'Laktasi' => ['lat' => '44.9075524', 'lng' => '17.2817192'], 'Bijeljina' => ['lat' => '44.760706', 'lng' => '19.1697901'], 'Mostar' => ['lat' => '43.3395487', 'lng' => '17.786221'], 'Sarajevo' => ['lat' => '43.3395487', 'lng' => '17.786221'], 'Pale' => ['lat' => '43.8174955', 'lng' => '18.5493794'], 'Prijedor' => ['lat' => '44.9828959', 'lng' => '16.6664094'], 'Prnjavor' => ['lat' => '44.8688679', 'lng' => '17.6325089'], 'Novi Sad' => ['lat' => '45.2722076', 'lng' => '19.7794008']]; $users = App\User::get(); foreach ($users as $user) { $stations = factory(App\Station::class, 2)->make(); foreach ($stations as $station) { $position = array_shift($positions); $station->lat = $position['lat']; $station->lng = $position['lng']; } $user->stations()->saveMany($stations); } $tags = App\Tag::get(); $stations = App\Station::get(); foreach ($stations as $station) { $aerometrics = factory(App\Aerometric::class, 20)->make(); $station->tags()->sync($tags->random(3)->lists('id')->toArray()); $station->aerometrics()->saveMany($aerometrics); } }
/** * Run the database seeds. * * @return void */ public function run() { /* $shuffle = function($tags, $num) { $s=[]; while($num>0) { $s[] = $tags[$num]; $num--; } return $s; }; $max = $this->tag->count(); $tags = $this->tag->lists('id'); factory(App\Product::class, 15)->create()->each(function ($product) use ($max, $tags, $shuffle) { $product->tags()->attach($shuffle($tags, rand(1, $max - 1))); }); */ factory(App\Product::class, 15)->create()->each(function ($product) { $nrb_insert = rand(1, 4); $tab_result = array(); $nbr_tags = App\Tag::count(); $tab_result = array(); while ($nrb_insert != 0) { $candidat = rand(1, $nbr_tags); $test = array_search($candidat, $tab_result); if (!is_int($test)) { array_push($tab_result, $candidat); } $nrb_insert--; } foreach ($tab_result as $value) { $product->tags()->attach($value); } }); }
/** * Run the database seeds. * * @return void */ public function run() { // Generate users factory(App\User::class, 10)->create()->each(function (App\User $user) { $user->profileImage()->associate(factory(App\Image::class, 1)->make()); }); // Generate tags factory(App\Tag::class, 8)->create(); // Generate projects factory(App\Project::class, 16)->create()->each(function (App\Project $project) { // Associate with contributors and tags $project->tags()->saveMany(App\Tag::all()->random(random_int(2, 6))); $project->contributors()->saveMany(App\User::all()->random(2)); // Add content $project->colors()->saveMany(factory(App\Color::class, random_int(2, 5))->make()); $project->fonts()->saveMany(factory(App\Font::class, random_int(2, 3))->make()); $project->images()->saveMany(factory(App\Image::class, random_int(3, 5))->make()); $project->textures()->saveMany(factory(App\Texture::class, random_int(3, 5))->make()); }); // Generate comments factory(App\Comment::class, 20)->create(); // Generate notifications factory(App\Notification::class, 20)->create(); }
|-------------------------------------------------------------------------- | Routes File |-------------------------------------------------------------------------- | | Here is where you will register all of the routes in an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ use App\Task; use Illuminate\Http\Request; // Route::get('/', function () { // return view('welcome'); // }); Route::get('/tag/{id}', function ($id) { $project = App\Tag::find($id); echo $project->user; foreach ($project->projects as $tags) { echo $tags; } }); // Route::get('taskC', function(){ // echo 'task'; // $task = App\Task::find(1); // print_r($task); // }); /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- |
public function run() { App\Tag::truncate(); factory(App\Tag::class, 20)->create(); }
Route::get('blade', function () { return view('layouts.child'); }); Route::get('model', function () { $s = App\Staff::class; $r = $s::find(1); $rr = $r->photos; dump($rr); }); Route::get('model2', function () { /* * 多态多关联 * */ $post = App\Post::find(1); dump($post->tags->toArray()); $tag = App\Tag::find(1); dump($tag->posts->toArray()); }); /* * 关联查询 * */ Route::get('gl', function () { //有评论的文章 或者对于这个 是 有飞机的航线 //这个has获得的还是本表的内容 has只是个条件 不能获得子表内容 $f = App\Flight::has('fly')->get(); dump($f); //这个才是获得子表的结果 $fly = App\Flight::find(1)->fly; dump($fly->toArray()); //这个是错的'.'这个点不是这个表的单元 而是这个类的子关系 //比如 文章的->评论->投票 也就是获得评论的投票
Route::get('/', 'HomeController@getIndex'); Route::get('search', ['as' => 'search', 'uses' => 'HomeController@getSearch']); Route::get('contact', 'HomeController@getContact'); Route::post('contact', ['as' => 'post_contact', 'uses' => 'HomeController@postContact']); Route::get('feed', ['as' => 'feed', 'uses' => 'HomeController@getFeed']); Route::get('sitemap', 'HomeController@getSiteMap'); Route::get('{year}/{month}/{slug}', ['as' => 'post', 'uses' => 'HomeController@getPost'])->where(['year' => '[0-9]+', 'month' => '[0-9]+', 'slug' => '^[a-zA-Z0-9-]*$']); Route::get('category/{slug}', ['as' => 'category', 'uses' => 'HomeController@getCategory'])->where(['slug' => '^[a-zA-Z0-9-]*$']); Route::get('tag/{slug}', ['as' => 'tag', 'uses' => 'HomeController@getTag'])->where(['slug' => '^[a-zA-Z0-9-]*$']); Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function () { Route::get('auth/login', 'Auth\\AuthController@getLogin'); Route::post('auth/login', 'Auth\\AuthController@postLogin'); Route::controller('password', 'Auth\\PasswordController'); Route::group(['middleware' => 'auth'], function () { Route::get('/', 'HomeController@getIndex'); Route::get('auth/logout', 'Auth\\AuthController@getLogout'); Route::resource('posts', 'PostsController', ['except' => 'show']); Route::resource('users', 'UsersController', ['except' => 'show']); Route::controller('settings', 'SettingsController'); Route::get('clear-cache', 'CacheController@getClear'); }); }); Route::group(['prefix' => 'api', 'middleware' => 'auth'], function () { Route::get('tags/{term?}', function ($term) { if ($term !== null && strlen($term) >= 2) { $tags = App\Tag::where('name', 'LIKE', $term . '%')->get(); return response()->json(['status' => 'success', 'data' => $tags->toArray()]); } }); });
/** * Run the database seeds. * * @return void */ public function run() { /* * Prepare seeding */ $faker = Faker::create(); if (config('database.default') != 'sqlite') { DB::statement('SET FOREIGN_KEY_CHECKS=0'); } Model::unguard(); /* * Seeding users table */ App\User::truncate(); factory(App\User::class)->create(['name' => 'John Doe', 'email' => '*****@*****.**', 'password' => bcrypt('password')]); factory(App\User::class, 9)->create(); $this->command->info('users table seeded'); /** * Seeding roles table */ Bican\Roles\Models\Role::truncate(); DB::table('role_user')->truncate(); $adminRole = Bican\Roles\Models\Role::create(['name' => 'Admin', 'slug' => 'admin']); $memberRole = Bican\Roles\Models\Role::create(['name' => 'Member', 'slug' => 'member']); App\User::where('email', '!=', '*****@*****.**')->get()->map(function ($user) use($memberRole) { $user->attachRole($memberRole); }); App\User::whereEmail('*****@*****.**')->get()->map(function ($user) use($adminRole) { $user->attachRole($adminRole); }); $this->command->info('roles table seeded'); /* * Seeding articles table */ App\Article::truncate(); $users = App\User::all(); $users->each(function ($user) use($faker) { $user->articles()->save(factory(App\Article::class)->make()); $user->articles()->save(factory(App\Article::class)->make()); }); $this->command->info('articles table seeded'); /** * Seeding comments table */ App\Comment::truncate(); $articles = App\Article::all(); $articles->each(function ($article) use($faker, $users) { $article->comments()->save(factory(App\Comment::class)->make(['author_id' => $faker->randomElement($users->lists('id')->toArray())])); }); $this->command->info('comments table seeded'); /* * Seeding tags table */ App\Tag::truncate(); DB::table('article_tag')->truncate(); $rawTags = ['General', 'Laravel', 'Lumen', 'Eloquent', 'Servers', 'Tips', 'Lesson Feedback']; foreach ($rawTags as $tag) { App\Tag::create(['name' => $tag, 'slug' => str_slug($tag)]); } $tags = App\Tag::all(); foreach ($articles as $article) { $article->tags()->attach($faker->randomElements($tags->lists('id')->toArray(), $faker->randomElement([1, 2, 3]))); } $this->command->info('tags table seeded'); /* * Seeding attachments table */ App\Attachment::truncate(); if (!File::isDirectory(attachment_path())) { File::deleteDirectory(attachment_path(), true); } $articles->each(function ($article) use($faker) { $article->attachments()->save(factory(App\Attachment::class)->make()); }); $files = App\Attachment::lists('name'); if (!File::isDirectory(attachment_path())) { File::makeDirectory(attachment_path(), 777, true); } foreach ($files as $file) { File::put(attachment_path($file), ''); } $this->command->info('attachments table seeded'); /** * Close seeding */ Model::reguard(); if (config('database.default') != 'sqlite') { DB::statement('SET FOREIGN_KEY_CHECKS=1'); } }
public function update(Request $request, $id) { $station = \App\Station::findOrFail($id); if (!$request->user()->isAdmin() && $station->user_id != $request->user()->id) { return abort(403); } $this->validate($request, ['name' => 'required', 'description' => '', 'unique_id' => 'required|unique:stations,unique_id,' . $station->id, 'lat' => 'required', 'lng' => 'required']); $station->name = $request->input('name'); $station->description = $request->input('description', ''); $station->unique_id = $request->input('unique_id'); $station->lat = $request->input('lat'); $station->lng = $request->input('lng'); $station->save(); $tags = []; foreach ($request->get('tags', $station->tags()->lists('name')->toArray()) as $tag) { if ($tag == "") { continue; } $t = \App\Tag::where('name', $tag)->first(); if (!$t) { $t = new \App\Tag(); $t->name = strtolower($tag); $t->save(); } $tags[] = $t->id; } $station->tags()->sync(array_unique($tags)); return redirect('backend/stations/' . $station->id); }
<?php /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ //Route::get('/', ['as' => 'posts.index', 'uses' => 'PostsController@index']); //Route::post('/', ['as' => 'posts.store', 'uses' => 'PostsController@store']); Route::get('/', function () { return view('index'); }); Route::resource('api/posts', 'ApiController'); Route::resource('posts', 'PostsController'); Route::get('tag/{id}', ['as' => 'tags.list', 'uses' => function ($id) { $tag = App\Tag::find($id); return view('tags.list', ['tag' => $tag]); }]);