I have a small problem with redirecting a user once page is created.
Problem is that all together I have 3 returns within 2 functions and obviously that can't be done and I am looking for a way to change this but I don't know what should it be.
Process is like this.
User creates a page: code is saved into javascript variable. User chooses a name for a page: code is saved into another javascript variable.
Ajax is passing these values to Controller and then:
public function postDB(Request $request) {
$newName = $request->input('name_website');
$newLat = $request->input('newCode');
$websites = new Website();
$websites->name = $newName;
$websites->html = $newLat;
$websites->save();
return $newName;
return $this->website($newName);
}
public function website($newName)
{
dd($newName);
Website::where('name', $newName)->first()->html;
return view('layouts/website');
}
After saving into a database I am returning value of $newName which is the actual name for a website or I should say URL and also return (call another function) which then search for html code that matches a name, and return view that deals with displaying it:
@extends('layouts.master') @section('title', 'Website Builder') @section('content')
<meta name="csrf-token" content="" />
<script src="http://ift.tt/2hxDEqg"></script>
<script>
axios.get('/name').then(
html => document.querySelector('html').innerHTML = html
);
</script>
</html>
@endsection @show
So basically after user saved it to database I want to redirect them to a page which is in saved variable $newName and retrieve + display html that matches name that is in the variable.
Route::group(['middleware' => ['web']], function () {
Route::get('home', 'BuilderController@homepage');
Route::get('template', 'BuilderController@templates');
Route::post('template', 'BuilderController@postDB');
Route::get('logout', 'BuilderController@getLogout');
Route::get('/{name}', 'BuilderController@website');
});
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2l1K0Qq
via IFTTT
Aucun commentaire:
Enregistrer un commentaire