Reputation: 303
I wanted to call the file from the route on Laravel. I have a PostsController and inside there was a method name index. I created a folder inside views name posts and inside that created a file named index. I tried to print the variable into the index.blade.php file which i assigned into the PostsController, but got error. Can anyone help me. Here is my code
Route :
Route::post('/posts/index', 'PostsController@index');
Controller :
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PostsController extends Controller
{
public function index()
{
$nameIndex = "Testing";
return view('posts/index', [
'nameIndex' => $nameIndex
]);
}
}
view file : posts/index.blade.php
My name is : {{ $nameIndex }}
Upvotes: 3
Views: 156
Reputation: 1064
Laravel supports writing the view path using both dot or slash separator but you should be aware that this change from Linux to Windows
on Windows you use backslash
view('posts\index');
but on Linux
view('posts/index');
So it's better to use dot separator to avoid issues after hosting your code (mostly linux server)
view('posts.index');
Upvotes: 2