Remove duplicate titleurl check now we are using better sluggable method

This commit is contained in:
Jonny Barnes 2017-06-16 13:04:51 +01:00
parent 522f06162e
commit 9372059e1e

View file

@ -45,31 +45,19 @@ class ArticlesController extends Controller
$published = '0'; $published = '0';
} }
//if a `.md` is attached use that for the main content. //if a `.md` is attached use that for the main content.
$content = null; //set default value
if ($request->hasFile('article')) { if ($request->hasFile('article')) {
$file = $request->file('article')->openFile(); $file = $request->file('article')->openFile();
$content = $file->fread($file->getSize()); $content = $file->fread($file->getSize());
} }
$main = $content ?? $request->input('main'); $main = $content ?? $request->input('main');
try { $article = Article::create(
$article = Article::create( [
[ 'url' => $request->input('url'),
'url' => $request->input('url'), 'title' => $request->input('title'),
'title' => $request->input('title'), 'main' => $main,
'main' => $main, 'published' => $published,
'published' => $published, ]
] );
);
} catch (Exception $e) {
$msg = $e->getMessage();
$unique = strpos($msg, '1062');
if ($unique !== false) {
//We've checked for error 1062, i.e. duplicate titleurl
return redirect('/admin/blog/create')->withInput()->with('message', 'Duplicate title, please change');
}
//this isn't the error you're looking for
throw $e;
}
return redirect('/admin/blog'); return redirect('/admin/blog');
} }