/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $categories = $request->input('categories', []); $image = $request->input('image', ''); $this->validateMultipleLocaleData($request, ['name', 'url', 'description'], ['name' => 'required', 'url' => 'required'], $data, $successes, $fails, $old); $error_redirect = redirect(adminUrl('links/add'))->withInput(array_merge(['categories' => $categories, 'image' => $image], $old)); if (count($successes) <= 0 && count($fails) > 0) { return $error_redirect->withErrors($fails[0]); } $validator = Validator::make($request->all(), ['categories' => 'required|exists:categories,id,type,' . Category::LINK, 'image' => 'sometimes|url']); if ($validator->fails()) { return $error_redirect->withErrors($validator); } DB::beginTransaction(); try { $link = new Link(); $link->image = $image; foreach ($successes as $locale) { $transData = $data[$locale]; $trans = $link->translateOrNew($locale); $trans->name = $transData['name']; $trans->description = $transData['description']; $trans->url = $transData['url']; } $link->save(); if (count($categories) > 0) { $link->categories()->attach($categories); } DB::commit(); } catch (\Exception $e) { DB::rollBack(); return $error_redirect->withErrors([trans('error.database_insert') . ' (' . $e->getMessage() . ')']); } return redirect(adminUrl('links')); }
public function run() { $admin_access_permission = Permission::create(['name' => 'access-admin', 'display_name' => 'Access admin', 'description' => 'Access admin pages']); $owner_role = Role::create(array('name' => 'owner', 'display_name' => 'Owner', 'description' => 'Owner of the system', 'status' => Role::STATUS_HIDDEN)); $owner_role->attachPermission($admin_access_permission); $admin_role = Role::create(array('name' => 'admin', 'display_name' => 'Administrator', 'description' => 'Manage operation of the system and important modules')); $admin_role->attachPermission($admin_access_permission); $tester_role = Role::create(array('name' => 'tester', 'display_name' => 'Tester', 'description' => 'Tester of the system', 'status' => Role::STATUS_HIDDEN)); $tester_role->attachPermission($admin_access_permission); $user_role = Role::create(array('name' => 'user', 'display_name' => 'User', 'description' => 'Normal user')); // TODO: Add 1 administrator $owner = User::create(array('display_name' => 'Owner', 'name' => 'owner', 'email' => '*****@*****.**', 'password' => bcrypt(')^KM$bB-W7:Z@8eG'), 'url_avatar' => appDefaultUserProfilePicture(), 'url_avatar_thumb' => appDefaultUserProfilePicture(), 'activation_code' => str_random(32), 'active' => true)); $owner->attachRole($owner_role); $admin = User::create(array('display_name' => 'Administrator', 'name' => 'admin', 'email' => '*****@*****.**', 'password' => bcrypt('123456'), 'url_avatar' => appDefaultUserProfilePicture(), 'url_avatar_thumb' => appDefaultUserProfilePicture(), 'activation_code' => str_random(32), 'active' => true)); $admin->attachRoles([$admin_role, $owner_role]); $tester = User::create(array('display_name' => 'Tester', 'name' => 'tester', 'email' => '*****@*****.**', 'password' => bcrypt('123456'), 'url_avatar' => appDefaultUserProfilePicture(), 'url_avatar_thumb' => appDefaultUserProfilePicture(), 'activation_code' => str_random(32), 'active' => true)); $tester->attachRole($tester_role); $locales = ['en', 'vi']; $category = new Category(); $category->type = Category::LINK; $data = ['en' => ['name' => 'Example link category', 'slug' => 'example-link-category', 'description' => 'Example link category'], 'vi' => ['name' => 'Chuyên mục liên kết ví dụ', 'slug' => 'chuyen-muc-lien-ket-vi-du', 'description' => 'Chuyên mục liên kết ví dụ']]; foreach ($locales as $locale) { $transData = $data[$locale]; $trans = $category->translateOrNew($locale); $trans->name = $transData['name']; $trans->slug = $transData['slug']; $trans->description = $transData['description']; } $category->save(); $data = [['en' => ['name' => 'Author on Facebook', 'url' => 'https://www.facebook.com/linhntaim', 'description' => 'Author on Facebook'], 'vi' => ['name' => 'Hồ sơ tác giả trên Facebook', 'url' => 'https://www.facebook.com/linhntaim', 'description' => 'Hồ sơ tác giả trên Facebook']], ['en' => ['name' => 'Author\'s Personal Site', 'url' => 'http://linhntaim.com', 'description' => 'Author\'s Personal Site'], 'vi' => ['name' => 'Trang cá nhân của tác giả', 'url' => 'http://linhntaim.com', 'description' => 'Trang cá nhân của tác giả']], ['en' => ['name' => 'Katniss on Github', 'url' => 'https://github.com/linhntaim/katniss', 'description' => 'Katniss on Github'], 'vi' => ['name' => 'Katniss trên Github', 'url' => 'https://github.com/linhntaim/katniss', 'description' => 'Katniss trên Github']]]; foreach ($data as $item) { $link = new Link(); foreach ($locales as $locale) { $transData = $item[$locale]; $trans = $link->translateOrNew($locale); $trans->name = $transData['name']; $trans->description = $transData['description']; $trans->url = $transData['url']; } $link->save(); $link->categories()->attach($category->id); } ThemeWidget::create(['widget_name' => 'base_links', 'theme_name' => '', 'placeholder' => 'default_placeholder', 'constructing_data' => '{"category_id":"' . $category->id . '","en":{"name":"Widget named Base Links","description":""},"vi":{"name":"Ví dụ về Công cụ hiển thị Base Links","description":""}}', 'active' => true, 'order' => 1]); ThemeWidget::create(['widget_name' => 'extra_html', 'theme_name' => '', 'placeholder' => 'default_placeholder', 'constructing_data' => '{"en":{"name":"Widget named Extra HTML","description":"","content":"<p><strong>Lorem Ipsum<\\/strong><sup>®<\\/sup> is simply dummy text of the <em>printing and typesetting industry<\\/em>. <span style=\\"color:#FFFF00\\"><span style=\\"background-color:#000000\\">Lorem Ipsum<\\/span><\\/span> has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like <span style=\\"font-size:16px\\">Aldus PageMaker <\\/span>including versions of <em><strong><u>Lorem Ipsum<\\/u><\\/strong><\\/em>. <img alt=\\"smiley\\" src=\\"http:\\/\\/katniss.linhntaim.com\\/assets\\/libraries\\/ckeditor-4.5.5\\/plugins\\/smiley\\/images\\/regular_smile.png\\" style=\\"height:23px; width:23px\\" title=\\"smiley\\"><\\/p>\\r\\n\\r\\n<p><img alt=\\"\\" src=\\"http:\\/\\/katniss.linhntaim.com\\/files\\/user_2\\/katniss.png\\" style=\\"height:120px; width:120px\\"><\\/p>\\r\\n"},"vi":{"name":"V\\u00ed d\\u1ee5 v\\u1ec1 C\\u00f4ng c\\u1ee5 hi\\u1ec3n th\\u1ecb Extra HTML","description":"","content":"<p><strong>Lorem Ipsum<\\/strong><sup>®<\\/sup> is simply dummy text of the <em>printing and typesetting industry<\\/em>. <span style=\\"color:#FFFF00\\"><span style=\\"background-color:#000000\\">Lorem Ipsum<\\/span><\\/span> has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like <span style=\\"font-size:16px\\">Aldus PageMaker <\\/span>including versions of <em><strong><u>Lorem Ipsum<\\/u><\\/strong><\\/em>. <img alt=\\"smiley\\" src=\\"http:\\/\\/katniss.linhntaim.com\\/assets\\/libraries\\/ckeditor-4.5.5\\/plugins\\/smiley\\/images\\/regular_smile.png\\" style=\\"height:23px; width:23px\\" title=\\"smiley\\"><\\/p>\\r\\n\\r\\n<p><img alt=\\"\\" src=\\"http:\\/\\/katniss.linhntaim.com\\/files\\/user_2\\/katniss.png\\" style=\\"height:120px; width:120px\\"><\\/p>\\r\\n"}}', 'active' => true, 'order' => 2]); }