/** * Store a newly created resource in storage. * * @param SnippetsRequest|Request $request * @return \Illuminate\Http\Response */ public function store(SnippetsRequest $request) { //create snippet with all provided data $snippet = Snippet::create($request->all()); //create storage path $pathToSnippet = storage_path() . '/snippets/'; //add customer id to customer_snippet $snippet->customer()->attach($request->input('customer')); //create directory for snippet if (!File::isDirectory($pathToSnippet)) { File::makeDirectory($pathToSnippet); } File::makeDirectory($pathToSnippet . $snippet->slug); $snippet->path_to_material = $pathToSnippet . $snippet->slug; $snippet->save(); return redirect('snippets'); }
/** * Store a newly created resource in storage. * * @param SnippetRequest $request * @return Response */ public function store(SnippetRequest $request) { Snippet::create($request->all()); return redirect()->route('snippet.index')->with('message', 'Snippet well created.'); }