protected function findUrlByUri($uri) { try { $url = Url::findOrFail($uri); } catch (ModelNotFoundException $e) { throw new NotFoundHttpException(null, $e); } return $url; }
public function testResourceUrlDelete() { $resource = Resource::create(['title' => 'Test Deleting', 'uri' => 'test/deleting-1']); $resource->uri = 'test/deleting-2'; $resource->save(); $resource->uri = 'test/deleting-3'; $resource->save(); $resource->delete(); $url3 = Url::find('test/deleting-3'); $this->assertNull($url3, 'Url has not been properly deleted.'); $url2 = Url::find('test/deleting-2'); $this->assertNull($url2, 'Old Url has not been properly deleted.'); $url1 = Url::find('test/deleting-1'); $this->assertNull($url1, 'Old Url has not been properly deleted.'); }
/** * Modifies the $originalUrl to redirect to $newUrl. * * @param Url $originalUrl The URL that will be redirecting * @param Url $newUrl The URL that will be redirected to */ protected function redirectUrl(Url $originalUrl, Url $newUrl) { $newUrl->redirectsTo()->dissociate(); $newUrl->save(); $originalUrl->redirectsTo()->associate($newUrl); $originalUrl->save(); }