enter image description here
These are my files which is not showing my data in html only data is processing and no error also. I want to look my database through laravel in a html file but it's only processing and also not showing any error. so please help me on this error.
no error, the ajax response is good, but data not shown and processing box keeps showing.
Yajra 9.0
Laravel 5.8
MemberController.php
<?php
namespace App\Http\Controllers;
use App\Models\Member;
use Illuminate\Http\Request;
use Datatables;
use Validator;
class MemberController extends Controller
{
public function addSocialMember(){
return view("home.views.social-member");
}
public function listMember(){
return view("home.views.memberlist");
}
public function listAllMember(){
$memberlist = Member::query();
return Datatables::of($memberlist)->make(true);
}
public function saveMember(Request $request){
$validator = Validator::make(array(
"name"=>$request->name,
"email"=>$request->email,
"phone"=>$request->phone,
"state"=>$request->state,
"city"=>$request->city,
"issue"=>$request->issue,
"message"=>$request->message,
),array(
"name"=>"required",
"email"=>"required|unique:member",
"phone"=>"required",
"state"=>"required",
"city"=>"required",
"issue"=>"required",
"message"=>"required",
));
if($validator->fails()){
return redirect("social-member")->withErrors($validator)->withInput();
}else{
//successfully we have passed our form
$member = new Member;
$member->name = $request->name;
$member->email = $request->email;
$member->phone = $request->phone;
$member->state = $request->state;
$member->city = $request->city;
$member->issue = $request->issue;
$member->message = $request->message;
$member->save();
$request->session()->flash("message","Member has been submitted form successfully");
return redirect("social-member");
}
}
}
Memberlist.blade.php
#extends("home.layouts.layout")
#section("title","Social Member | Bheekho Foundation")
#section("content")
<div class="container padding-top-three">
<br/>
<blockquote><h4>We need Help</h4></blockquote>
<br/>
<div class="row">
<div class="col-md-12">
<table class="table table-striped table-bordered" id="memberlist">
<thead>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>State</th>
<th>City</th>
<th>Issue</th>
<th>Describe Your Issues</th>
<th>Status</th>
</thead>
</table>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3./jquery.min.js"></script>
#endsection
web.php
<?php
Route::get("/","HomeController#homepage");
//Social Member Route
Route::get("/social-member","MemberController#addSocialMember")->name("addsocialmember");
Route::get("/memberlist","MemberController#listMember")->name("listmember");
Route::get("/memberlist-data","MemberController#listAllMember")->name("listallmember");
Route::post("/save-member","MemberController#saveMember")->name("savemember");
Related
I wont to fetch data from database and show them in a view page as a table. I tried so many ways and didn't work. Also I have used member adding form as a model in my home.blade.php and it works fine.
here is my home.blade.php
<!-- show tasks -->
<div class="container-fluid">
<div class="container mt-4">
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">ID</th>
<th scope="col">Task</th>
<th scope="col">Assigned Date</th>
<th socpe="col">Sign-off Date</th>
<th socpe="col">Edit/Delete</th>
</tr>
</thead>
#foreach($tasks as $task)
<tr>
<td>{{$task->id}}</td>
<td>{{$task->task}}</td>
<td>{{$task->assigned_date}}</td>
<td>{{$task->end_date}}</td>
<td>
Delete
Edite
</td>
</tr>
#endforeach
</table>
</div>
</div>
<!-- end Show tasks -->
here is my taskController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\task;
class taskController extends Controller
{
public function store(Request $request){
$this->validate($request,[
'task'=>['required', 'max:100', 'min:5'],
'assignedDate' => ['required', 'date'],
'endDate' => ['required', 'date'],
]);
$task = new task;
$task->task = $request->task;
$task->assigned_date = $request->assignedDate;
$task->end_date = $request->endDate;
$task->save();
return redirect()->back()->with('message', 'Task added successfuly');
}
public function getdata()
{
$data=task::all();
return view('home')->with('tasks', $data);
}
}
and here is my web.php
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});
Route::post('/saveTask', 'taskcontroller#store');
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
So, What am I doing wrong here? Can somebody please explain me?
Change your Last Route to
Route::get('/home', 'HomeController#getdata')->name('home');
I've been working on the search function for my library application, which is my first Laravel project so I am kinda struggling.
I have finally figured out the search function, where I can search for a book by its title, however, I can't display any data from the search that is not in that table.
If I run the search I get the following error message:
Facade\Ignition\Exceptions\ViewException
Undefined property: stdClass::$authors (View: /Users/krisz/code/project/resources/views/books/index.blade.php)
I have created a pivot table between 'books' and 'authors' and if I want to display the data only on my index page without searching it works, but after searching I cannot get it to work.
Also, if I delete all the data from my index.blade.php which is outside the "books" table the search works correctly.
Could you please help me with this problem?
BookController:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Book;
use App\Language;
use App\Genre;
use App\Author;
use App\Publisher;
use App\User;
use Illuminate\Support\Facades\DB;
class BookController extends Controller
{
public function index(Request $request)
{
$books = Book::with('language')->get();
$books = Book::with('user')->get();
$languages = Language::all();
$genres = Genre::all();
$publishers = Publisher::all();
$users = User::all();
$authors = Author::all();
return view('books/index', compact('books','languages','genres','publishers','users'));
}
public function search(Request $request)
{
$authors = Author::all();
$books = Book::with('language')->get();
$books = Book::with('user')->get();
$languages = Language::all();
$genres = Genre::all();
$publishers = Publisher::all();
$users = User::all();
$search = $request->get('search');
$books = DB::table('books')
->where('title','like','%' .$search. '%')
->paginate(5);
return view('books/index')
->with(compact('books','languages','genres','authors','publishers','users'));
}
}
index.blade.php:
#extends('layout')
#section('title')
<title>Alle Bücher</title>
#section('content')
<style>
.uper {
margin-top: 40px;
}
</style>
<div class="uper">
#if(session()->get('success'))
<div class="alert alert-success">
{{ session()->get('success') }}
</div><br />
#endif
<div align="left">
<div class="col-md-4">
<h1>Policy</h1>
</div>
<div class="col-md-4">
<form action="{{ route('search') }}" method="get" role="search">
{{ csrf_field() }}
<div class="input-group">
<input type="text" class="form-control" name="search" placeholder="Search Title" <span class="input-group-btn">
<button type="submit" class="btn btn-primary">Search</button></span>
</div>
</form>
</div>
</div>
<table class="table table-hover">
<thead>
<tr>
<td>ID</td>
<td>Titel</td>
<td colspan="2">Autor</td>
<td>Jahr</td>
<td colspan="2">Verlag</td>
<td colspan="2">Genre</td>
<td>Sprache</td>
<td>ISBN</td>
<td>Seitenzahl</td>
<td>Ausgeliehen von:</td>
<td colspan="2">Funktionen</td>
</tr>
</thead>
<tbody>
#foreach($books as $book)
<tr>
<td>{{$book->id}}</td>
<td>{{$book->title}}</td>
#foreach($book->authors as $author)
<td>{{$author->name}}</td>
#endforeach
<td>{{$book->year}}</td>
#foreach($book->publishers as $publisher)
<td>{{$publisher->name}}</td>
#endforeach
#foreach($book->genres as $genre)
<td>{{$genre->name}}</td>
#endforeach
<td>{{$book->language->name}}</td>
<td>{{$book->isbn}}</td>
<td>{{$book->pages}}</td>
<td>{{$book->user->name}}</td>
<td>Bearbeiten</td>
<td>
<form action="{{ route('books.destroy', $book->id)}}" method="post">
#csrf
#method('DELETE')
<button class="btn btn-danger" type="submit">Löschen</button>
</form>
</td>
</tr>
#endforeach
</tbody>
</table>
<div>
#endsection
Book Model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Book extends Model
{
protected $fillable = ['title', 'year', 'language_id', 'isbn', 'pages', 'user_id'];
public function publishers(){
return $this->belongsToMany(Publisher::class);
}
public function authors(){
return $this->belongsToMany(Author::class);
}
public function genres(){
return $this->belongsToMany(Genre::class);
}
public function language(){
return $this->belongsTo(Language::class);
}
public function user(){
return $this->belongsTo(User::class);
}
}
First, you're just overwriting yourself here:
$books = Book::with('language')->get();
$books = Book::with('user')->get();
I suspect you want both language and user, and you probably want the authors, as well as some other data you try to fetch in the view? This is called eager loading and it's done on multiple relationships like this:
$books = Book::with(['language', 'user', 'authors', 'publishers', 'genres'])->get();
Not sure about the error you're getting, as $book should be an instance of App\Book and not stdClass, and relations should still be available even if not eager loaded. I suspect there's some code you're not showing or your models are not defined correctly.
I need some help getting my user_id from my pdf_files table, but for some reason it keep giving me an empty array when I try using $request = all() --> return me {} and dd($downloads) return me this Collection {#233 ▼ #items: [] }. Do I have to use with statement or anything? I saw some people using it but do I really need it? Thanks for helping
Code:
Controller:
public function downfunc(Request $request){
// $downloads = new pdfFile;
$downloads=pdfFile::where('user_id', $request->user_id)->get();
//$downloads=DB::table('pdf_files')->get(); --> this code return results
//dd($downloads);
//return $request->all();
return view('download.viewfile',compact('downloads'));
}
download.blade.php
<table class="table table-bordered">
<thead>
<th>Name of File</th>
<th>Action</th>
</thead>
<tbody>
#foreach($downloads as $down)
<tr>
<td>{{$down->file_name}}</td>
<td>
<a href="download/{{$down->file_name}}" download="{{$down->file_name}}">
<button type="button" class="btn btn-primary">
<i class="glyphicon glyphicon-download">
Download
</i>
</button>
</a>
</td>
</tr>
#endforeach
</tbody>
</table>
pdfFile model:
protected $fillable = array('file_name','file_size','user_id');
public function personal_infos() {
return $this->belongsTo('App\personal_info', 'user_id', 'id');
}
Please make sure your $request->user_id is valid
You can check by run sql manually.
I'm using Laravel 5.2 and trying to do an add and delete a data that I already Inputted but when i clicked "Delete" button it gave me NotFoundHttpException.
Here's example of my delete function code in controller:
<?php
namespace App\Http\Controllers\Track;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
//use Illuminate\Support\Facades\Input;
use Validator;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Track as Track;
class TrackController extends Controller
{
/*Display track registry*/
public function index()
{
$data = array('track' => Track::all());
return view('admin.dashboard.tracks.track',$data);
}
/*Display create track form*/
public function create()
{
return view('admin.dashboard.tracks.createtrack');
}
/*Save data form*/
public function saveTrack(Request $request)
{
$input = $request->all();
$messages = array(
'trackCode.required'=>'Track code required.',
'trackCode.unique'=>'Track code already exist.',
'trackName.required'=>'Track name required.',
);
$rule = array(
'trackCode' => 'required|unique:track',
'trackName' => 'required|max:60',
);
$validator = Validator::make($input, $rule, $messages);
if($validator->fails()) {
#Directed to the same page with error message
return Redirect::back()->withErrors($validator)->withInput();
#Validate Success
}
$track = new Track;
$track->trackCode = $request['trackCode'];
$track->trackName = $request['trackName'];
if (! $track->save())
App::abort(500);
return Redirect::action('Track\TrackController#index')->with('successMessage','Track data "'.$input['trackName'].'" has been inserted.');
}
/*Delete data*/
public function delete($id)
{
echo $id;
/*$trackCode = Track::where('trackCode','=',$id)->first();
if($trackCode==null)
App::abort(404);
$trackCode->delete();
return Redirect::action('track');*/
}
}
and here's the part of my delete option code:
<div class="box-body">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th style="width: 150px; text-align: center;">Track Code</th>
<th>Track Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
#foreach($track as $itemTrack)
<tr id="track-list" name="track-list">
<td style="text-align: center;">{{ $itemTrack->trackCode }}</td>
<td>{{ $itemTrack->trackName }}</td>
<td><a href="{{{ action('Track\TrackController#delete',[$itemTrack->trackCode]) }}}" title="Delete" onclick="return confirm('Are you sure you want to delete this track : {{{$itemTrack->trackCode.' - '.$itemTrack->trackName }}}?')">
<span class="label label-danger"><i class="fa fa-trash"> Delete </i></span>
</a>
</td>
</tr>
#endforeach
</tbody>
</table>
<br/>
<button class="btn btn-success pull-right" type="submit">Add Data</button>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
whenever it appears the data and i try to delete it, it went to a page and there's NotFoundHttpException error instead of showing me the $id of the data.
Can someone help and explain? thanks
-Edited part-
Routes:
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::group(['middleware' => 'web'], function()
{
Route::auth();
});
//Route as admin
Route::group(['middleware' => ['web','role:admin']], function()
{
Route::get('/users/dashboard', 'UserController#index');
/*-----------------------------------------------Track Part---------------------------------------------------------*/
/*Track index*/
Route::get('/users/programs/track', array('as'=>'track', 'uses'=>'Track\TrackController#index'));
/*Create track form*/
Route::get('/users/programs/track/create', array('as'=>'track.create', 'uses'=>'Track\TrackController#create'));
/*Route to save track*/
Route::post('/users/programs/track/save', array('as'=>'track.save', 'uses'=>'Track\TrackController#saveTrack'));
/*Delete track*/
Route::get('/users/programs/track/{$id}/delete', array('as'=>'track.delete', 'uses'=>'Track\TrackController#delete'));
/*-----------------------------------------------Course Part---------------------------------------------------------*/
//Display course menu
Route::get('/users/programs/course', array('as'=>'course', 'uses'=>'Course\CourseController#index'));
//Delete course data
Route::get('/users/programs/course/{$id}/delete', array('as'=>'course.delete', 'uses'=>'Course\CourseController#delete'));
//Create course data
Route::post('/users/programs/course/create', array('as'=>'course.create', 'uses'=>'Course\CourseController#createCourse'));
//Edit course data
Route::get('/users/programs/course/{$id}/edit', array('as'=>'course.edit', 'uses'=>'Course\CourseController#editCourse'));
//Save editted course data
Route::put('/users/programs/course/{$id}/saveEdit', array('as'=>'course.saveEdit', 'uses'=>'Course\CourseController#saveEdit'));
});
I'm guessing that you are using DELETE in your route, which wouldn't work with an a link. You'd need to create a form and spoof the DELETE. You can find more about doing it here.
Alternatively, you can change Route::delete() to Route::get(), but this isn't recommended.
I think this could be do to with your triple braces. Try {{ action('Track\TrackController#create') }} instead.
More information read this link
Try this:
{!! action('track.delete',[$itemTrack->trackCode]) !!}
From documentation:
"If the method accepts route parameters, you may pass them as the second argument to the method:
$url = action('UserController#profile', ['id' => 1]);"
I guess 'id' wasn`t defined properly. Try this:
action('Track\TrackController#delete',['id' => $itemTrack->trackCode])
Replace delete Anchor tag with this:-
<a href="{{ url('users/programs/track/'.$itemTrack->trackCode.'/delete') }}" title="Delete" onclick="return confirm('Are you sure you want to delete this track : {{{$itemTrack->trackCode.' - '.$itemTrack->trackName }}}?')">
And change the delete Route:-
Route::match(['get', 'post'], '/users/programs/track/{id?}/delete', 'Track\#TrackController#delete');
Hope it Helps!
I created a management system in codeigniter that loads data from the database in datatables for specific suppliers. When the user clicks at any of these data rows he is navigating to each supplier's company products. My problem is that I want to find a session or something else that will keep the data of the previous selected rows when the page reloads. At the moment I am using flashdata but when I go back a step or return to the previous page all the data from the database disappear. What I want is something that will keep my data even if I am reloading the page or if I go back a step.
That's my controller:
public function __construct() {
parent::__construct();
$this->load->library('form_validation');
$this->load->model('dash_match_model');
$this->session->keep_flashdata('supplier_id');
$this->session->keep_flashdata('segment');
$this->session->keep_flashdata('class');
$this->session->keep_flashdata('commodity');
$this->load->library('session');
$this->load->helper('url');
}
public function index() {
$arr['page']='dash1';
$user_id = $this->session->userdata('id');
$supplier = $this->dash_match_model->dash_present_all_suppliers($user_id);
$arr['dash_present_all_suppliers'] = $supplier;
$this->load->view('clients/clDashboard',$arr);
}
public function select_supplier()
{
$supplier_name = $this->input->get('name', TRUE);
$supplier_sel = $this->dash_match_model->selected_supplier_id($supplier_name);
foreach ($supplier_sel->result() as $row){
$this->session->set_flashdata('supplier_id', $row->supplier_id);
}
$selected_supplier = $this->dash_match_model->unspsc_matched_skus($this->session->flashdata('supplier_id'));
$arr['dash_present_all_selected_suppliers'] = $selected_supplier;
$this->load->view('clients/unspscSegment', $arr);
}
public function select_segment(){
$segment = $this->input->get('segment', TRUE);
$supplier_id = $this->session->flashdata('supplier_id');
$this->session->set_flashdata('segment', $segment);
$segment_sel =$this->session->flashdata('segment');
$selected_segment = $this->dash_match_model->unspsc_class($supplier_id, $segment_sel);
$arr['dash_present_all_selected_segments'] = $selected_segment;
$this->load->view('clients/unspscClass', $arr);
}
public function select_class(){
$class = $this->input->get('class', TRUE);
$supplier_id = $this->session->flashdata('supplier_id');
$segment_sel =$this->session->flashdata('segment');
$this->session->set_flashdata('class', $class);
$class_sel = $this->session->flashdata('class');
$selected_class =$this->dash_match_model->unspsc_commodity($supplier_id, $segment_sel, $class_sel);
$arr['dash_present_all_selected_class'] = $selected_class;
$this->load->view('clients/unsspscCommodity', $arr);
That's one of my first table view file with suppliers:
<div class="row-fluid sortable">
<div class="box span12">
<div class="box-header" data-original-title>
<div class="box-icon">
<i class="halflings-icon wrench"></i>
<i class="halflings-icon chevron-up"></i>
<i class="halflings-icon remove"></i>
</div>
</div>
<div class="box-content">
<table id="suppliertable" class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th>Supplier</th>
<th>Open Range</th>
<th>Fill Content</th>
<th>Total Match</th>
</tr>
</thead>
<tbody>
<?php foreach($dash_present_all_suppliers as $v): ?>
<tr>
<td class="center" style="color:#0c595b;"><?php echo $v['supplierCompany']?> </td>
<td class="center">70%</td>
<td class="center">12%</td>
<td class="center">82%</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div><!--/span-->
</div>
Instead of using $this->session->flashdata() user the normal session i.e. $this->session->userdata() to store the temp browse data and write a cron which will delete this session in a regular interval or at the time of logout or any desired specific action.
Hope this will give better approach n help you in solving your problem