Ejemplo n.º 1
0
 public function routeIsUnique($attribute, $value, $parameters, Validator $validator)
 {
     $validator->setFallbackMessages(array_merge($validator->getFallbackMessages(), ['unique_route' => 'this route already exists']));
     $validates = false;
     $value = Handle::normalizeUrl($value);
     try {
         $routes = Route::getRoutes();
         $request = Request::create($value);
         $routes->match($request);
         // route exists
     } catch (\Exception $e) {
         // route doesn't exist
         $validates = true;
     }
     return $validates;
 }
Ejemplo n.º 2
0
 /**
  * @covers \Ohio\Content\Handle\Handle::__toString
  * @covers \Ohio\Content\Handle\Handle::setUrlAttribute
  * @covers \Ohio\Content\Handle\Handle::handleable
  * @covers \Ohio\Content\Handle\Handle::normalizeUrl
  */
 public function test()
 {
     # normalizeUrl
     $this->assertEquals('one', Handle::normalizeUrl('One'));
     $this->assertEquals('one/123/what-just-happened', Handle::normalizeUrl("One/123!!!/What Just Happened?"));
     Page::unguard();
     $page = factory(Page::class)->make();
     $page->id = 1;
     Handle::unguard();
     $handle = factory(Handle::class)->make();
     $handle->handleable_id = 1;
     $handle->handleable_type = $page->getMorphClass();
     $handle->url = ' /Test/test it all ';
     $handle->delta = 1;
     $handle->handleable()->add($page);
     $attributes = $handle->getAttributes();
     # handleable relationship
     //$this->assertInstanceOf(Page::class, $handle->handleable);
     # setters
     $this->assertEquals('test/test-it-all', $handle->__toString());
     $this->assertEquals('test/test-it-all', $attributes['url']);
     $this->assertEquals('content/page', $attributes['handleable_type']);
 }
Ejemplo n.º 3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Requests\CreateRequest $request
  *
  * @return \Illuminate\Http\Response
  */
 public function store(Requests\CreateRequest $request)
 {
     $handle = $this->handle->create($request->only(['handleable_id', 'handleable_type', 'url']));
     return response()->json($handle);
 }