Laravel radio form - laravel

i'm trying to implement this payment,changing the user->pay from a default value of 0 to 1,hoW? pressing the checkbox and changing his value. This will log into videos that can be watched only from that customers. Every time i try to enter the url ( i'm logged already ) it redirects to the home :(
PaymentsController.php
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class PaymentsController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
/**
*
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$user = Auth::user();
return view('home',compact('user'));
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show()
{
return view('sub.payment')->with(Auth::user());
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit(User $User)
{
return view('sub.payment', compact('user'));
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, User $user)
{
$request->validate([
'pay'=>'required']);
$user->pay = $request->pay;
$user->save();
return redirect()->route('/home')->with('success', 'Congratulazioni per l/abbonamento!');
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
web.php
Route::get('/payments', [App\Http\Controllers\PaymentsController::class,'update'])->name('payments.update');
payment.blade.php
#extends('layouts.app')
#section('content')
<div class="container" style="background: rgb(12, 22, 28)">
<div class="card1"style="justify-content:center">
<header class="header">
<h1>ESTREMI PER IL PAGAMENTO</h1>
</header>
<div class="payment">
<div class="card">
<ul class="list-group list-group-flush">
<li class="list-group-item"><h5>IL TUO PIANO</h5></li>
<li class="list-group-item"><p> Paghi 29,99£</p></li>
</ul>
<label for="name" class="label1">{{ __('Nome') }}</label>
<input id="name" type="text" class="input1" name="name" value="{{ Auth::user()->name }}">
<label for="surname" class="label1">{{ __('Descrizione del video') }}</label>
<input id="surname" type="text" class="input1" name="surname" value="{{ Auth::user()->surname }}">
<form method="POST" action="{{ route('payment.update', $user) }}">
<main class="primoInput" style="position:relative;">
#method('PUT') #csrf
<input type="checkbox" id="coding" name="pay" value="1">
<label for="coding">Accetta </label>
<div class="card-body">
<p class="card-text"id="condizioni">
Codice di sicurezza Creando un account accetti che il tuo abbonamento abbia inizio immediatamente e confermi di aver letto e accettato le nostre Condizioni di utilizzo e l'Informativa sulla privacy e sui cookie. Il tuo abbonamento verrà rinnovato automaticamente al costo di 29,99 € e la quota ti sarà addebitata mensilmente tramite il metodo di pagamento da te scelto, fino a quando non deciderai di disdirlo. Puoi disdire in qualsiasi momento, ogni mese, selezionando “Disdici abbonamento” da “Il mio account”.
</p>
<button type="submit" class="buttonBig"> {{ __('ATTIVA ABBONAMENTO') }}</button>
</div>
</form>
</div>
</div>
</div>
</div>
#endsection

Related

How to implement a simple search function for laravel CRUD

When I click the search button, this shows.
error image
It shows Error Exception for (Cannot use object of type Illuminate\Database\MySqlConnection as array )
<div class='container'>
<div class="row" >
<div class="col-md-12">
<br />
<h3 align="center">Data Pesakit</h3>
<br />
#if($message = Session::get('success'))
<div class="alert alert-success">
<p>{{$message}}</p>
</div>
#endif
<div align="right">
Add
<br />
<br />
</div>
<div class="col-md-12">
<form action="/search" method="get" class="d-none d-md-inline-block form-inline ml-auto mr-0 mr-md-3 my-2 my-md-0">
<div class="form-group">
<input class="form-control" type="search" name="search" />
<span class="form-group-btn">
<button class="btn btn-primary" type="submit">Search</button>
</span>
</div>
</form>
</div>
<table class="table table-bordered">
<tr>
<th>Nama Pertama</th>
<th>Nama Akhir</th>
<th>Kad Pengenalan</th>
<th>No Telefon</th>
<th>Alamat Rumah</th>
<th>Alamat Email</th>
<th>Edit</th>
<th>Delete</th>
</tr>
#foreach($pesakit as $row)
<tr>
<td>{{$row['namaPertama']}}</td>
<td>{{$row['namaAkhir']}}</td>
<td>{{$row['kadPengenalan']}}</td>
<td>{{$row['noTelefon']}}</td>
<td>{{$row['alamatRumah']}}</td>
<td>{{$row['email']}}</td>
<td>Edit</td>
<td><form method="post" class="delete_form" action="{{action('PesakitController#destroy',$row['id'])}}">
{{csrf_field()}}
<input type="hidden" name="_method" value="DELETE" />
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
#endforeach
</table>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('.delete_form').on('submit', function(){
if(confirm("Are you sure you want to delete it?"))
{
return true;
}
else
{
return false;
}
});
});
</script>
#endsection
This is code for views
class PesakitController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$pesakit = Pesakit::all()->toArray();
return view('pesakit.index', compact('pesakit'));
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('pesakit.create');
}
public function search(Request $request)
{
$search = $request->get('search');
$pesakit = DB::table('pesakit')
->where('namaPertama', 'like', '%'.$search. '%');
return view('pesakit.index', ['pesakit'=>$pesakit]);
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'namaPertama' => 'required',
'namaAkhir' => 'required',
'kadPengenalan' => 'required',
'noTelefon' => 'required',
'alamatRumah' => 'required',
'email' => 'required'
]);
$pesakit = new Pesakit([
'namaPertama' => $request->get('namaPertama'),
'namaAkhir' => $request->get('namaAkhir'),
'kadPengenalan' => $request->get('kadPengenalan'),
'noTelefon' => $request->get('noTelefon'),
'alamatRumah' => $request->get('alamatRumah'),
'email' => $request->get('email')
]);
$pesakit->save();
return redirect()->route('pesakit.create')->with('success',
'Data Berjaya Disimpan');
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
$pesakit = Pesakit::find($id);
return view('pesakit.edit', compact('pesakit', 'id'));
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$this->validate($request, [
'noTelefon' => 'required',
'alamatRumah' => 'required'
]);
$pesakit = Pesakit::find($id);
$pesakit->noTelefon = $request->get('noTelefon');
$pesakit->alamatRumah = $request->get('alamatRumah');
$pesakit->save();
return redirect()->route('pesakit.index')->with('success', 'Data Dikemas kini');
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
$pesakit = Pesakit::find($id);
$pesakit->delete();
return redirect()->route('pesakit.index')->with('success', 'Data Deleted');
}
}
This is the controller
Route::get('/', function () {
return view('utama');
});
Route::resource('pesakit', 'PesakitController');
Route::resource('petugas', 'PetugasController');
Route::resource('pendaftaran', 'PendaftaranController');
Route::get('/search','PesakitController#search');
This is the Route
I try to look for simple error such as ; or misspell or something but i cannot find it. It says some array problem but does not all crud is array??
add get()
public function search(Request $request)
{
$search = $request->get('search');
$pesakit = DB::table('pesakit')
->where('namaPertama', 'like', '%'.$search. '%')->get();
return view('pesakit.index', ['pesakit'=>$pesakit]);
}

how to autofill a form with id from a previous form

I have a previous form in which i created a user and technician. the data is well filled in the tables of the database. Now the form redirects me to another form in which the technician id is needed. I'm working to make the technician id in the new form auto filled from the previous form. I hope my question is clear and I which you could help me. I put my code and the form I want to be auto-filled.Hope you could help me.
Model1
public function tarificationtache()
{
return $this->belongsToMany('App\tarificationtache','technicien_tarificationtache','technicien_id','tarificationtache_id');
}
Model2
public function techniciens()
{
return $this->belongsToMany('App\technicien','technicien_tarificationtache','tarificationtache_id','technicien_id');
}
technicien.Controller
public function store(Request $request)
{
$user = new user();
$user->nom = $request->input('nom');
$user->prenom = $request->input('prenom');
$user->tel = $request->input('tel');
$user->mobil = $request->input('mobil');
$user->role = $request->input('role');
$user->email = $request->input('email');
$user->password = $request->input('password');
$user->save();
$technicien = new technicien();
$technicien->user_id = $user->id;
$technicien->actif = $request->input('actif');
$technicien->moyenne_avis = $request->input('moyenne_avis');
$technicien->save();
$technicien->zoneintervention()->attach($request->zoneintervention_id);
$technicien->metier()->attach($request->metier_id);
return redirect('tarification/create');
}
tarification.controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\tarificationtache;
use App\technicien;
use App\tache;
class TarificationController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$Listtache=tache::orderBy('libelle_tache')->get();
$Listtarification=tarificationtache::all();
return view('tarification.index',
['tarification'=>$Listtarification]);
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
$techniciens = technicien::orderBy('id','desc')->get();
$taches = Tache::orderBy('id', 'desc')->get();
return view('tarification.create')->with('taches', $taches)->with('techniciens', $techniciens);
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$tarification = new tarificationtache();
$tarification ->tache_id = $request->input('tache_id');
$tarification ->Tarif =$request->input('Tarif');
$tarification->save();
$tarification->techniciens()->attach($request->technicien_id);
return redirect('tarification');
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
$tache=Tache::find($id);
return view('tache.edit',['libelle_tache'=>$tache],
['Tarif'=>$tache],['metier_id'=>$tache]);
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
$tache =Tache::find($id);
$tache->delete();
return redirect('tache');
}
}
View
#extends('Layouts/app')
#section('content')
#if(count($errors))
<div class="alert alert-danger" role="alert">
<ul>
#foreach($errors ->all() as $message)
<li>{{$message}}</li>
#endforeach
</ul>
</div>
#endif
<div class="container">
<div class="row"></div>
<div class="col-md-12">
<form action=" {{url ('tarification') }}" method="post">
{{csrf_field()}}
<div class="form-group">
<label for="technicien">Technicien</label>
<select name="technicien_id" id="technicien" class="form-control" >
#foreach($techniciens as $techniciens)
<option value="{{ $techniciens->id }}">
{{$techniciens->id}}
</option>
#endforeach
</select>
</div>
<div class="form-group">
<label for="Tache">Libelle Tache</label>
<select name="tache_id" id="Tache" class="form-control">
#foreach($taches as $tache)
<option value="{{ $tache->id }}">
{{$tache->libelle_tache}}
</option>
#endforeach
</select>
</div>
<div class="form-group">
<label for="">Tarif</label>
<input type="text" name ="Tarif" class="form-control"value="{{old('tarif')}}">
</div>
<div class="form-group">
<input type="submit" value = "enregistrer" class="form-control btn btn-primary">
</div>
</form>
</div>
</div>
<script>
#endsection
technicien.controller
public function store(Request $request)
{
$user = new user();
$user->nom = $request->input('nom');
$user->prenom = $request->input('prenom');
$user->tel = $request->input('tel');
$user->mobil = $request->input('mobil');
$user->role = $request->input('role');
$user->email = $request->input('email');
$user->password = $request->input('password');
$user->save();
$technicien = new technicien();
$technicien->user_id = $user->id;
$technicien->actif = $request->input('actif');
$technicien->moyenne_avis = $request->input('moyenne_avis');
$technicien->save();
$technicien->zoneintervention()->attach($request->zoneintervention_id);
$technicien_id = $technicien->id;
return redirect('tarification/create')->with(‘technicien_id’, $technicien_id);
}
tarification.view
<div class="form-group">
<label for="technicien">Technicien</label>
<select name="technicien_id" id="technicien"
class="form-control" >
#foreach($techniciens as $techniciens)
<option value="{{ $techniciens->id }}">
{{ $technicien_id }}
</option>
#endforeach
</select>
</div>
here is my new code i did exactly as you told me
You have to pass that value to the view.
$technician_id = $user->id;
return view(‘tarification/create’)->with(‘technician_id’, $technician_id);
Now you can use this value in your view.
<div class="form-group">
<label for="technicien">Technicien</label>
<input type="text" value={{$technician_id}} >
</div>

How to do multiple selection and insert them into database

I would like to make a multiple selection through the combobox and insert them into the database. the idea is to make an array and then make his appeal.
with what I've made, a single choice adds to the base. Would anyone have any idea how to insert all zones selected into my database.Thanks
Model 1
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class zoneintervention extends Model
{
public function techniciens()
{
return $this-
belongsToMany('App\technicien','technicien_zone','zoneintervention_id','technicien_id');
}
}
Model 2
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class technicien extends Model
{
public function zoneintervention()
{
return $this-
belongsToMany('App\zoneintervention','technicien_zone','technicien_id','z
oneintervention_id');
}
public function tarificationtache()
{
return $this->hasMany(Tarificationtache::class);
}
}
Controler
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\technicien;
use App\zoneintervention;
class TechnicienController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$Listzone=zoneintervention::orderBy('code_postal')->get();
$Listtechnicien=technicien::all();
return view('technicien.index',['technicien'=>$Listtechnicien]);
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
$zoneintervention = Zoneintervention::orderBy('id', 'desc')-
>get();
return view('technicien.create')->with('zoneintervention',
$zoneintervention);
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$technicien = new technicien();
$technicien ->actif =$request->input('actif');
$technicien ->moyenne_avis =$request->input('moyenne_avis');
$technicien = new technicien();
$technicien->actif = $request->input('actif');
$technicien->moyenne_avis = $request->input('moyenne_avis');
$technicien->save();
$technicien->zoneintervention()->attach($request-
>zoneintervention_id);
return redirect('technicien');
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
create
#extends('Layouts/app')
#section('content')
#if(count($errors))
<div class="alert alert-danger" role="alert">
<ul>
#foreach($errors ->all() as $message)
<li>{{$message}}</li>
#endforeach
</ul>
</div>
#endif
<div class="container">
<div class="row"></div>
<div class="col-md-12">
<form action=" {{url ('technicien') }}" method="post">
{{csrf_field()}}
<div class="form-group">
<label for="zoneintervention">zoneintervention</label>
<select multiple name="zoneintervention_id"
id="zoneintervention" class="form-control" >
#foreach($zoneintervention as
$zoneintervention)
<option value="{{ $zoneintervention->id }}">
{{$zoneintervention->code_postal}}
</option>
#endforeach
</select>
</div>
<div class="form-group">
<label for="">Moyenne Avis</label>
<input type="text" name ="moyenne_avis" class="form-
control"value="{{old('moyenne_avis')}}">
</div>
<div class="form-group">
<label for="">Etat</label>
<input type="text" name ="actif" class="form-
control"value="{{old('actif')}}">
</div>
<div class="form-group">
<input type="submit" value = "enregistrer"
class="form-control btn btn-primary">
</div>
</form>
</div>
</div>
#endsection
In your blade file you can do:
...
<select multiple name="zoneintervention_id[]" id="zoneintervention" class="form-control" >
...
In your controller,
public function store(Request $request)
{
//This will give you an array of all the selected item
dd($request['zoneintervention_id']);
}

Laravel Invalid datetime format: 1366 Incorrect integer value:

I have two tables, a table "métier" and a table "tâche" with one to many connection, a "métier" has several "tâche". In my form "ajouter tâches" I have a combobox from which I choose the "métier" associated with the "tâche".
now i just want to fill the combo from the table metier with libelle_metier an then add the id of libelle_metier that i chosen to the table tache and then add it to metier_id.Any help ?
Model metier
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class metier extends Model
{
public function metier()
{
return $this->hasMany(Tache::class);
}
}
Model metier
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class tache extends Model
{
public function metier()
{
return $this->belongsTo(Metier::class);
}
public function tarificationtache()
{
return $this->hasMany(Tarificationtache::class);
}
}
tache.blade.php
#extends('Layouts/app')
#section('content')
#if(count($errors))
<div class="alert alert-danger" role="alert">
<ul>
#foreach($errors ->all() as $message)
<li>{{$message}}</li>
#endforeach
</ul>
</div>
#endif
<div class="container">
<div class="row"></div>
<div class="col-md-12">
<form action=" {{url ('tache') }}" method="post">
{{csrf_field()}}
<div class="form-group">
<label for="">Libelle Tache</label>
<input type="text" name ="libelle_tache"
class="form-control"value="{{old('libelle_tache')}}">
</div>
<div class="form-group">
<label for="">Tarif</label>
<input type="text" name ="Tarif" class="form-
control"value="{{old('tarif')}}">
</div>
<div class="form-group">
<label for="metier">metier</label>
<select name="metier_id" id="metier" class="form-
control">
#foreach($metiers as $metier)
<option value="{{$metier}}">
{{$metier->libelle_metier}}
</option>
#endforeach
</select>
</div>
<div class="form-group">
<input type="submit" value = "enregistrer"
class="form-control btn btn-primary">
</div>
</form>
</div>
</div>
<script>
#endsection
tache controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Tache;
use App\Metier;
class TacheController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$Listmetier=metier::orderBy('libelle_metier')->get();
$Listtache=tache::all();
return view('tache.index',['tache'=>$Listtache]);
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
//$metiers = Costcenter::lists('libelle_metier', 'id');
$metiers = Metier::orderBy('id', 'desc')->get();
return view('tache.create')->with('metiers', $metiers);
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$tache = new Tache();
$tache ->libelle_tache =$request->input('libelle_tache');
$tache ->Tarif =$request->input('Tarif');
$tache ->metier_id = $request->input('metier_id');
$tache->save();
return redirect('tache');
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
$tache=Tache::find($id);
return view('tache.edit',['libelle_tache'=>$metier],
['Tarif'=>$tache]);
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
$tache =Tache::find($id);
$tache->delete();
return redirect('tache');
}
}
If I understood you correctly you want to pass metier id where you loop over metiers you need to change
tache.blade.php
...
<option value="{{ $metier->id }}">
...

use multiple for loops in a td element in laravel

Hello guys i have 3 eloquent tables members, pledge and campaign and they are have a relationship amongst each other namely:
for member model
protected $table = "members";
public function loans()
{
return $this->hasMany(Loan::class, 'borrower_id', 'id');
}
public function user()
{
return $this->hasOne(User::class, 'id', 'user_id');
}
public function pledges()
{
return $this->hasMany(Pledge::class, 'member_id', 'id');
}
for campaign
protected $table = "campaigns";
public function pledges()
{
return $this->hasMany(Pledge::class, 'campaign_id', 'id')->orderBy('created_at', 'desc');
}
}
then for pledge model
protected $table = "pledges";
public function campaign()
{
return $this->hasOne(Campaign::class, 'id', 'campaign_id');
}
public function member()
{
return $this->hasOne(Member::class, 'id', 'member_id');
}
}
IN the plegde.create.blade
<div class="control-group">
<label class="control-label">Member</label>
<div class="controls">
<select>
#foreach ($member as $members)
<option>{{ $members->first_name }}</option>
#endforeach
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">Campaign</label>
<div class="controls">
<select>
#foreach ($campaign as $campaigns)
<option>{{ $campaigns->name }}</option>
#endforeach
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">Amount</label>
<div class="controls">
<input type="number" name="amount" id="required" value="{{ old('amount') }}">
#if ($errors->has('amount'))
<p class="alert alert-danger">{{ $errors->first('amount') }}
#endif
</div>
</div>
<div class="control-group">
<label class="control-label">Date (mm-dd)</label>
<div class="controls">
<div data-date="2012-11-02" class="input-append date datepicker">
<input type="text" name="date" value="2012-11-02" data-date-format="yyyy-mm-dd" class="span11" value="{{ old('date') }}">
#if ($errors->has('date'))
<p class="alert alert-danger">{{ $errors->first('date') }}
#endif
<span class="add-on"><i class="icon-th"></i></span> </div>
</div>
</div>
<div class="control-group">
<label class="control-label">Description</label>
<div class="controls">
<input type="text" name="notes" id="required" value="{{ old('notes') }}">
#if ($errors->has('notes'))
<p class="alert alert-danger">{{ $errors->first('notes') }}
#endif
</div>
</div>
<div class="form-actions">
<input type="submit" class="btn btn-success">
</div>
</form>
then in my pledge.index.blade.php i have this but it is not showing proerly this is the code
<div class="widget-content nopadding">
<table class="table table-bordered data-table">
<thead>
<tr>
<th>#ID</th>
<th>Campaign</th>
<th>Member</th>
<th>Amount</th>
<th>Date</th>
<th>Notes</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr class="gradeX">
#foreach ($member as $members)
<td>{{ $members->first_name }}</td>
#endforeach
#foreach ($campaign as $campaigns)
<td>{{ $campaigns->name }}</td>
#endforeach
#foreach ($pledge as $pledges)
<td>{{ $pledges->amount }}</td>
#endforeach
#foreach ($pledge as $pledges)
<td>{{ $pledges->date }}</td>
#endforeach
</tr>
</tbody>
</table>
</div>
Any help would be appreciated.
These are the controllers
Campaign Controller
use App\Campaign;
use Illuminate\Http\Request;
class CampaignController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$campaign = Campaign::all();
return view('campaign.index', compact('campaign'));
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('campaign.create');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'name'=>'required',
'goal'=> 'required',
]);
// return $request->all();
$campaign = new Campaign;
$campaign->name = $request->name;
$campaign->goal = $request->goal;
$campaign->notes= $request->notes;
$campaign->save();
return redirect (route('campaign.index'));
}
PLedge Controller
use App\Campaign;
use App\Member;
use App\Pledge;
use Illuminate\Http\Request;
class Pledgecontroller extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$member= Member::all();
$campaign= Campaign::all();
$pledge= Pledge::all();
return view ('pledges.index', compact ('member', 'campaign', 'pledge'));
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
$member= Member::all();
$campaign= Campaign::all();
$pledge= Pledge::all();
return view ('pledges.create', compact ('member', 'campaign', 'pledge'));
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$pledge= new Pledge;
$pledge->member_id = $request->member_id;
$pledge->campaign_id = $request->campaign_id;
$pledge->amount = $request->amount;
$pledge->date = $request->date;
$pledge->notes = $request->notes;
$pledge->save();
return redirect (route('pledge.index'));
// return $request->all();
}
Member Controller
use App\Member;
use Illuminate\Http\Request;
class MemberController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$member = Member::all();
return view('member.index', compact('member'));
// return view ('member.data');
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view ('member.create');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'first_name'=> 'required',
'middle_name'=>'required',
'last_name'=>'required',
'gender'=> 'required',
'marital_status'=> 'required',
'status'=> 'required',
'mobile_phone'=> 'required',
'address'=> 'required',
'email'=> 'required',
'dob'=> 'required',
'photo'=> 'required | image|mimes:jpeg,png,jpg,gif,svg|max:700',
]);
if ($request->hasFile('photo')) {
// $request->photo->store('public');
$imageName= $request->photo->store('public');
}
$member = new Member;
$member->first_name = $request->first_name;
$member->middle_name = $request->middle_name;
// $member->photo = $request->photo;
$member->photo = $imageName;
$member->last_name = $request->last_name;
$member->gender = $request->gender;
$member->marital_status = $request->marital_status;
$member->status = $request->status;
$member->mobile_phone = $request->mobile_phone;
$member->address = $request->address;
$member->email = $request->email;
$member->dob = $request->dob;
$member->save();
return redirect (route('member.index'));
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
$member = Member::where('id', $id)->get();
return view ('member.edit', compact('member'));
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$this->validate($request, [
'first_name'=> 'required',
'middle_name'=>'required',
'last_name'=>'required',
'gender'=> 'required',
'marital_status'=> 'required',
'status'=> 'required',
'mobile_phone'=> 'required',
'address'=> 'required',
'email'=> 'required',
'dob'=> 'required',
'photo'=> 'required | image|mimes:jpeg,png,jpg,gif,svg|max:700',
]);
if ($request->hasFile('photo')) {
// $request->photo->store('public');
$imageName= $request->photo->store('public');
}
$member = Member::find($id);
$member->first_name = $request->first_name;
$member->middle_name = $request->middle_name;
// $member->photo = $request->photo;
$member->photo = $imageName;
$member->last_name = $request->last_name;
$member->gender = $request->gender;
$member->marital_status = $request->marital_status;
$member->status = $request->status;
$member->mobile_phone = $request->mobile_phone;
$member->address = $request->address;
$member->email = $request->email;
$member->dob = $request->dob;
$member->save();
return redirect (route('member.index'));
// return $request->all();
}
This is not a good solution. Same table, different models, different foreachs.
You can make just one foreach and function. Like this:
public function memberFunction()
{
return $this->hasOne('App\Member');
}
//
public function campaignFunction()
{
return $this->hasOne('App\Campaign');
}
We made the connection as a function. Now inside the foreach use the function with [' '] tags.
#foreach ($example as $examples)
<td>{{ $examples->memberFunction['firstname'] }}</td>
<td> {{ $examples->campaignFunction['name'] }} </td>
#endforeach
you can continue like this.

Resources