this is my laravel project, the is a problem named undefined variable
it is funny I think the route is ok and Controller is also fine
route
Auth::routes();
Route::get('/', 'PagesController#home')->middleware('auth')->middleware('assign');
Route::get('/home', 'HomeController#index')->name('home')->middleware('auth');
Route::get('/groupchat', 'PagesController#getGroupchatPage')->name('groupchat')->middleware('auth');
Route::get('/groupsearch', 'PagesController#getGroupsearchPage')->name('groupsearch')->middleware('auth');
Route::get('/statistics', 'PagesController#getStatisticsPage')->name('statistics')->middleware('auth');
//Route::get('/author_views.statisticsA', 'PagesController#getStatisticsAdmin')->name('statisticsA')->middleware('auth');
// Routes for SQL Controller Querys
Route::get('/getQuestions/{id}', 'QuestionsController#getQuestions');
Route::get('/getChapterQuestions/{id}', 'QuestionsController#getChapterQuestions');
Route::get('/getAnswers/{id}', 'AnswersController#getAnswers');
Route::get('/getChapters/{id}', 'ChaptersController#getChapters');
Route::get('/countMembers/{id}', 'GroupsMembersController#countMembers');
Route::get('/getGroupMembers/{id}', 'GroupsMembersController#getGroupMembers');
Route::get('/getGroups/{id}', 'GroupsController#getGroups');
Route::get('/groupChapters/{id}', 'GroupsChaptersController#groupChapters');
Route::get('/getChaptersAndGroup/{id}', 'ChaptersController#getChaptersAndGroup');
Route::get('/getGroupsChaptersMembersKombined/{id}', 'ChaptersController#getGroupsChaptersMembersKombined');
// 28.06.2021
Route::get('/statistics', 'StatisticsController#statistic');
Route::get('/statisticsA', 'StatisticsController#statisticA');
Route::get('/admin', [
'uses' => 'PagesController#getAdminPage',
'as' => 'admin',
'middleware' => 'roles',
'roles' => ['Admin'],
])->middleware('auth');
Route::post('/admin_assign', [
'uses' => 'PagesController#postAdminAssignRoles',
'as' => 'admin_assign',
'middleware' => 'roles',
'roles' => ['Admin'],
])->middleware('auth');
Route::get('/statisticsA', [
'uses' => 'PagesController#getStatisticsAdmin',
'as' => 'statisticsA',
'middleware' => 'roles',
'roles' => ['Author','Admin']
])->middleware('auth');
Route::get('/eventA', [
'uses' => 'PagesController#getEventAdmin',
'as' => 'eventA',
'middleware' => 'roles',
'roles' => ['Author','Admin'],
])->middleware('auth');
and my blade
#extends('layouts.appAuthor')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('DozentAnsicht') }}</div>
<div class="card-body">
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif
<table id="statisticforteacher" class="table-responsive">
<thead>
<th>Id</th>
<th>FrageBezeichnung</th>
<th>Kapitel</th>
<th>richtige Antwort</th>
<th>falsche Antwort</th>
<th>Richtige Rate</th>
</thead>
<tbody>
#foreach($daten as $value)
<tr>
<td>{{$value -> Id}}</td>
<td>{{$value -> FrageBezeichnung}}</td>
<td>{{$value -> Kapitel}}</td>
<td>{{$value -> richtigeAntwort}}</td>
<td>{{$value -> falscheAntwort}}</td>
<td>{{$value -> richtigeRate}}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
I want to show the table in the view, but it didn't work in statisticA but it works in statistic
I don't know what happen
my controller
<?php
namespace App\Http\Controllers;
use DB;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class StatisticsController extends Controller
{
//
public function statistic(){
$data =DB::table('statisticforteacher') -> get();
return view('/statistics',compact('data'));
}
public function statisticA(){
$daten =DB::table('statisticforteacher') -> get();
return view('/statisticsA',compact('daten'));
}
}
has anyone a idea?
You have in route file two different routes with same url but different controllers. As in order when Laravel read the file, get the last matched route, for that reason you have the issue. So, fix your routes statements and must work
Route::get('/statisticsA', 'StatisticsController#statisticA');
Route::get('/statisticsA', [
'uses' => 'PagesController#getStatisticsAdmin',
'as' => 'statisticsA',
'middleware' => 'roles',
'roles' => ['Author','Admin']
])->middleware('auth');
Related
This question already has answers here:
Can't retrieve url GET parameters with Laravel 5.1on remote server
(2 answers)
Closed 2 years ago.
I have a search form that is sending a GET request to the method that it is using to view the form:
<form class="form-horizontal" method="GET" action="{{ route('LoggedIn.StudentModule.StudentHomeWork.index') }}">
<div class="form-group form-group-sm">
<div class="col-sm-3">
<input type="text" name="inputdate" class="form-control datepicker" placeholder="Date" >
</div>
<div class="col-sm-2">
<button class="btn btn-primary btn-sm btn-block" type="submit">
<i class="fa fa-search" aria-hidden="true"></i>
Search
</button>
</div>
</div>
</form>
And the route:
Route::group(array(
'middleware' => 'auth',
'prefix' => '!',
'namespace' => 'LoggedIn',
'as' => 'LoggedIn.',
), function() {
.................
Route::group(array(
'prefix' => 'StudentModule',
'namespace' => 'StudentModule',
'as' => 'StudentModule.'
), function () {
............
Route::group(array(
'prefix' => 'StudentHomeWork',
'as' => 'StudentHomeWork.',
), function () {
Route::get('/', array(
'as' => 'index',
'uses' => 'StudentHomeWorkController#index'
));
});
..................
});
...............
});
And my controller:
public function index()
{
$searchParam = request('inputdate') ? request('inputdate') : date('Y-m-d');
echo $searchParam; // this is showing no data
}
The problem is, i couldn't get the data from submitted form. I have used every option that i found in stackoverflow but couldn't get the data. Can anyone point me out what i am missing! My laravel version is 5.1
Note: I am using this method in Laravel 5.8 + 6. Which is working just fine
Try This
How To Pass GET Parameters To Laravel From With GET Method ?
Route::get('any', ['as' => 'index', 'uses' => 'StudentHomeWorkController#index']);
Then Controller
public function index(){
$searchParam = Input::get('category', 'default category');
}
Form:
{{ Form::open(['route' => 'any', 'method' => 'GET'])}}
<input type="text" name="inputdate"/>
{{ Form::submit('submit') }}
{{ Form::close() }}
There Also various method...
Change it as your need.. You can also pass it in url like:
Route::get('any/{data}','StudentHomeWorkController#index')->name('something);
Controller:
public function index($data){
print_r($data);
}
Hope it will help
I'm new in Laravel and now I'm trying to make link in my blade files.
I read that in many tutorials, you can just use href="{{route('mm-admin/blog')}}" to make it works.
And by works I mean the list should be like this "mm-admin/blog".
But what i get using that code is "mm-admin/mm-admin/blog".
I tried to remove the mm-admin from this code "route('mm-admin/blog')" and it returns error saying
blog isn't defined.
what is wrong with my code??
this is my blade file
<li class="{{ request()->is('mm-admin/dashboard') ? 'active' : '' }}">
<a href="{{route('dashboard')}}">
<i class="fas fa-home"></i> <span>Dashboard</span>
</a>
</li>
and this is my web route
Route::group(['prefix' => 'mm-admin', 'as' => 'mm-admin.'], function () {
Route::get('/', 'Admin\LoginController#showLoginForm')->name('login');
Route::get('/login', 'Admin\LoginController#showLoginForm')->name('login');
Route::post('/proseslogin', 'Admin\LoginController#login');
Route::get('/blog', [
'as' => 'blog',
'uses' => 'Admin\BlogController#index', 'middleware' => 'admin',
]);
});
This should work:
href="{{route('mm-admin.blog')}}"
I have just created the form and action is PagesController#check and the validation is as follows:
#extends('layout')
#section('content')
<div class = "container">
{!! Form::open(['action' => 'PagesController#check' , 'method' => 'POST']) !!}
<div class = "form-group">
{{ Form::label('country','Country')}}
{{ Form::text('country','', ['class' => 'form-control' , 'placeholder' => ''])}}
</div>
<div class = "form-group">
{{ Form::label('age','Age')}}
{{ Form::number('age','', ['class' => 'form-control' , 'placeholder' => ''])}}
</div>
<div class = "form-group">
{{ Form::label('marks','Marks')}}
{{ Form::number('marks','', ['class' => 'form-control' , 'placeholder' => ''])}}
</div>
<div class = "form-group">
{{ Form::label('description','Description')}}
{{ Form::textarea('description','', ['class' => 'form-control' , 'placeholder' => ''])}}
</div>
{{ Form::submit('Submit' , ['class' => 'btn btn-primary'])}}
{!! Form::close() !!}
</div>
#endsection
And the check() method in the PagesController is like this:
public function check(Request $request){
$this->validate($request, [
'country' => 'required',
'age' => 'required',
'marks' => 'required',
'description' => 'required'
]);
return 123;
}
Why is it then it is throwing the following error:
(2/2) ErrorException
Action App\Http\Controllers\PagesController#check not defined. (View: C:\wamp64\bin\apache\apache2.4.23\htdocs\website\resources\views\profiles.blade.php)
Here is the whole PagesController controller:
class PagesController extends Controller
{
public function home() {
return view('welcome');
}
public function about() {
$title = 'This is the about page';
return view('about')->with('title',$title);
}
public function show() {
$yomads = person::all();
return view('show')->with('yomads',$yomads);
}
public function profiles(){
return view('profiles');
}
public function check(Request $request){
$this->validate($request, [
'country' => 'required',
'age' => 'required',
'marks' => 'required',
'description' => 'required'
]);
return 123;
}
}
The error most likely has to do with the route (or lack of it) in app/Http/routes.php - check that it is properly defined there.
Furthermore, it is good practice to create custom request classes. Have a look at Form Request Validation
These can be generated with artisan:
php artisan make:request Profile
Then use it, as you were using the standard request:
public function check(ProfileRequest $request) {
[...]
When I try to load my project on web browser. It shows header and footer, but the middle section containing form is missing, and I don't understand what am I doing wrong?
views/welcome.blade:
<!DOCTYPE html>
<html lang="en">
<head>
#include('partials._head')
</head>
<body>
#include('partials._nav')
<div class="container">
#include('partials._messages')
#yield('content')
#include('partials._footer')
</div>
#include('partials._javascript')
</body>
</html>
views/user_auth/user_register.blade:
#extends('welcome')
#section('title')
Welcome!!
#endsection
#section('content')
{!! Form::open(['route' => 'signup']) !!}
{{ Form::label('user_name','Name:') }}
{{ Form::text('user_name',null,['class' => 'form-control']) }}
{{ Form::label('email','E-mail:') }}
{{ Form::text('email',null,['class' => 'form-control']) }}
{{ Form::label('mobile_num','Mobile No.:') }}
{{ Form::text('mobile_num',null,['class' => 'form-control']) }}
{{ Form::label('address','Address:') }}
{{ Form::text('address',null,['class' => 'form-control']) }}
{{ Form::label('state','State:') }}
{{ Form::text('state',null,['class' => 'form-control']) }}
{{ Form::label('city','City:') }}
{{ Form::text('city',null,['class' => 'form-control']) }}
{{ Form::label('district','District:') }}
{{ Form::text('district',null,['class' => 'form-control']) }}
{{ Form::submit('Register',array('class' => 'btn btn-success btn-lg btn- block form-spacing-top')) }}
{!! Form::close() !!}
#endsection
RegisterController:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class RegisterController extends Controller
{
public function getRegistrationPage()
{
return view('user_auth.user_register');
}
public function postSignUp(Request $request)
{
$this -> validate($request,[
'email' => 'required|email|unique:users',
'name' => 'required|max:20',
'mobile_num' => 'required|digits:10',
'address' => 'required',
'city' => 'required',
'district' => 'required',
'state' => 'required',
'password' => 'required|min:4'
]);
$email = $request['email'];
$name = $request['name'];
$mobile_num = $request['mobile_num'];
$address = $request['address'];
$city = $request['city'];
$district = $request['district'];
$state = $request['state'];
$password = bcrypt($request['password']);
$user = new User();
$user->email =$email;
$user->name = $name;
$user->mobile_num = $mobile_num;
$user->address = $address;
$user->city = $city;
$user->district = $district;
$user->state = $state;
$user->password = $password;
$user->save();
return redirect()->route('dashboard');
Auth::login($user);
}
public function postSignIn(Request $request)
{
$this -> validate($request,[
'mobile_num' => 'required',
'password' => 'required'
]);
if(Auth::attempt(['mobile_num' => $request['mobile_num'], 'password' => $request['password']])) {
return redirect()->route('dashboard');
}
return redirect()->back();
}
public function getDashboard()
{
return view('pages.dashboard');
}
}
routes/web.php :
Route::group(['middleware' => ['web']], function(){
Route::get('/', function () {
return view('welcome');
})->name('home');
Route::post('/signup',[
'uses' => 'RegisterController#postSignUp',
'as' => 'signup'
]);
Route::post('/signin',[
'uses' => 'RegisterController#postSignIn',
'as' => 'signin'
]);
Route::get('/dashboard',[
'uses' => 'RegisterController#getDashboard',
'as' => 'dashboard',
'middleware' => 'auth'
]);
Route::get('/register',[
'uses' => 'RegisterController#getRegistrationPage',
'as' => 'register',
'middleware' => 'auth'
]);
});
You need to return user_register view which should extend layout (in this case it called welcome):
#extends('welcome')
Or you can call welcome and include user_register view:
#include('user_auth.user_register')
It depends on what you want to achieve, but renaming welcome to layout and extending it looks like right solution here.
Also rename files to .blade.php, because now names are like welcome.blade instead of welcome.blade.php.
Your code is correct but Please check your route file Have you called user_register route?
You have set a welcome page as a layout file so When you will call welcome page it displays only header & footer file which you have included.
I'm new with Laravel and I'm having problems while I try to detach some values from my pivot tables.
The pivot tables I'm woking with are:
excercise_workout (ejercicio_rutina) & excise_day (ejercicio_dia) (those tables have just two id's each one). The relations are ManyToMany. A workout have a lot of days and a day have a lot of excercises.
I've created these routes:
Route::resource('rutinas','RutinasController');
Route::delete('rutinas.destroyEjercicio/{id}','RutinasController#destroyEjercicio');
I have this button that is a form and call the delete:
{!! Form::open([
'method' => 'DELETE',
'action' => [ 'RutinasController#destroyEjercicio', $ejercicio->id ]
]) !!}
{!! Form::submit('Borrar Ejercicio', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
The destroyEjercicio is the part I don't know how to hadle with:
public function destroyEjercicio($id)
{
$ejercicio = Ejercicio::findOrFail($id);
dias()->$ejercicio->detach($id);
//EXAMPLE DELETE WITH QUERY
// DB::delete('delete from toy_user where toy_id = ? AND user_id = ? AND status = 0', array($toy->id,Auth::id()));
return redirect('rutinas');
}
I recieve this error when I try to submit the delete form:
Call to undefined function App\Http\Controllers\dias()
I've tried a lot of other methods but I don't know how to do it.
I need to know the ID of the day and the ID of the excercise I want to delete. And I don't know how the past it by the post request.
UPDATE -> THIS IS THE FORM I DO NOT HAVE INPUTS TO REQUEST...
#foreach ($rutina->dias as $dia)
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel-body">
Ejercicios para el <strong>{{ $dia->nombre }}</strong>
<hr>
#foreach ($dia->ejercicios as $ejercicio)
<ul>
<li>{{ $ejercicio->nombre }}</li>
</ul>
{!! Form::open([
'method' => 'DELETE',
'action' => [ 'RutinasController#destroyEjercicio', $ejercicio->id ]
]) !!}
{!! Form::submit('Borrar Ejercicio', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
#endforeach
</div>
</div>
</div>
#endforeach
You need something like this:
public function destroyEjercicio($ejercicioId, $diasId)
{
$ejercicio = Ejercicio::findOrFail($ejercicioId);
$ejercicio->dias()->detach($diasId);
https://laravel.com/docs/5.1/eloquent-relationships#inserting-many-to-many-relationships
Update
How to use Request object. If you're using forms, Reuqest object will contain all form fields. Just do something like this:
public function destroyEjercicio(Request $request)
{
$ejercicioId = $request->get('ejercicioIdField');
$diasId = $request->get('diasIdField');
I solved this the following way. First I create this new route:
Route::post('rutinas.destroyEjercicio/{ejercicioId}/{diaId}', [
'as' => 'destroy',
'uses' => 'RutinasController#destroyEjercicio'
]);
You must add this array at the form:
{!! Form::open([
'method' => 'POST',
*******'route' => ['destroy', $ejercicio->id, $dia->id]******
]) !!}
{!! Form::submit('Borrar Ejercicio', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
Then in your controller you pass the two id's that you need:
public function destroyEjercicio($ejercicioId, $diaId)
{
$ejercicio = Ejercicio::findOrFail($ejercicioId);
$ejercicio->dias()->detach($diaId);
return redirect('rutinas');
}