/** * Define your route model bindings, pattern filters, etc. * * @param \Illuminate\Routing\Router $router * @return void */ public function boot(Router $router) { parent::boot($router); \Route::bind('category', function ($value) { return \App\Model\Option::where('id', $value)->first(); }); }
/** * 储存文件并返回记录 * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file * @return static */ public static function create(array $attributes) { $file = $attributes['file']; $fileinfo = ['ext' => $file->getClientOriginalExtension(), 'name' => $file->getClientOriginalName(), 'mime' => $file->getMimeType(), 'size' => $file->getSize(), 'savename' => $file->getBasename()]; $file->move(self::path()); $attributes['title'] = $fileinfo['name']; $attributes['value'] = json_encode($fileinfo); return Option::create($attributes); }
/** * Run the database seeds. * * @return void */ public function run() { $options = [['name' => 'php', 'title' => 'php'], ['name' => 'site', 'title' => '网站']]; foreach ($options as $option) { $option['type'] = 'tag'; $option['value'] = ''; \App\Model\Option::create($option); } }
function option($key, $default = '') { $options = Cache::get('options'); if (!array_get($options, $key)) { Cache::put('options', \App\Model\Option::all()->lists('value', 'key'), config('app.option_exp', 10)); $options = Cache::get('options'); } return array_get($options, $key, $default); }
/** * Run the database seeds. * * @return void */ public function run() { $options = [['name' => 'blog', 'title' => '博文'], ['name' => 'bbs', 'title' => '交流区']]; foreach ($options as $option) { $option['type'] = 'category'; $option['value'] = ''; \App\Model\Option::create($option); } }
public function actionUpdate() { $httpRequest = $this->context->getService('httpRequest'); if ($this->option->get('cron') != $httpRequest->getQuery('cron')) { throw new \Nette\Application\BadRequestException("Invalid request"); } $feeds = $this->feed->get_all(); foreach ($feeds as $feed) { try { $articles = $this->feed->parse_articles($feed->id); $this->article->add_multiple($articles); // Debugger::dump($articles); // exit; } catch (\Exception $e) { $this->error->save($feed->id, $e); } libxml_clear_errors(); } $this->terminate(); }
public function postLunbo() { $options = $this->request()->only(['lb_image1', 'lb_url1', 'lb_title1', 'lb_image2', 'lb_url2', 'lb_title2', 'lb_image3', 'lb_url3', 'lb_title3']); try { transaction(); foreach ($options as $key => $option) { Option::where('key', $key)->update(['value' => $option]); } commit(); return $this->success('保存成功'); } catch (\Exception $exception) { rollback(); } return $this->error('修改失败,请稍后再试'); }
/** * Register any other events for your application. * * @param \Illuminate\Contracts\Events\Dispatcher $events * @return void */ public function boot(DispatcherContract $events) { parent::boot($events); Category::saved(function ($cat) { Cache::forget('cat'); }); Link::saved(function ($link) { Cache::forget('link'); }); Ad::saved(function ($ad) { Cache::forget('ad'); }); Option::saved(function ($ad) { Cache::forget('config'); }); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $post = \App\Model\Post::find($id); return view('post/edit')->with('type', 'update')->with('post', $post)->with('categorys', \App\Model\Option::whereType('category')->get()); }
/** * Display a listing of the resource. * * @return Response */ public function index() { return view('category/list')->with('categorys', \App\Model\Option::whereType('category')->get()); }