I am facing undefined variable error when trying to access a variable in my view. I have gone through several solutions out here but none of them has worked for me. I have thoroughly examined everything that could cause this error in mu code and cannot find anything at all, please assist
Controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Product;
use App\Category;
use App\Depot;
use Illuminate\Support\Facades\DB;
use Gloudemans\Shoppingcart\Facades\Cart;
use Auth;
class CheckoutController extends Controller
{
public function index()
{
$allcategories=Category::get();
$delivery_method = DB::table('deliverymethods')
->get();
$cartItems=Cart::content();
return view('checkout.index',['delivery_method'=>$delivery_method],['allcategories'=>$allcategories]);
}
public function deliverymethod()
{
$cartItems=Cart::content();
$allcategories=Category::get();
return view('delivery.index',['cartItems'=>$cartItems],['allcategories'=>$allcategories]);
}
public function billinginfo()
{
$depots=Depot::get();
$cartItems=Cart::content();
$allcategories=Category::get();
return view('billing.index',compact('cartItems'),['allcategories'=>$allcategories],['depots'=>$depots]);
}
public function shipping(Request $request)
{
$user_id=Auth::user()->id;
$shippingaddress=DB::table('shippingaddresses')
->select('shippingaddresses.*')
->where('user_id',$user_id)
->get();
$cartItems=Cart::content();
$allcategories=Category::get();
return view('shipping.index',['cartItems'=>$cartItems],['allcategories'=>$allcategories],['shippingaddress'=>$shippingaddress]);
}
}
My View
#extends('home.base')
#section('action-content')
<div class="container">
<div class="container" id="cart-window">
<div class="row">
<div class="col-lg-12" id="cart-header">
<h3>Billing & Shipping Details <span class="cart-return pull-right"><i class="ionicons ion-ios-cart"></i> Back to Cart</h3>
</div>
</div>
<div class="row">
<div class="col-lg-9">
#if(Cart::Count()==0)
<div class="row">
<div class="col-lg-12" id="empty-cart">
<p>Your cart is currently empty</p>
</div>
</div>
<div class="row">
<div class="col-lg-12">
Return to Shop
</div>
</div>
#else
<div class="card detail" id="delivery-card">
<div class="card-header">
</div>
<div class="card-body">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-lg-6">
<h5><strong>Existing Addresses</strong></h5>
</div>
<div class="col-lg-6">
<select class="select2 form-control" id="newAddress">
<option selected disabled>Please Select Delivery Address</option>
<option value="0">Add New Address</option>
#foreach($shippingaddress as $depot)
<option value="{{$depot->depot_name}}">{{$depot->depot_name}}</option>
#endforeach
<option>LIGHt</option>
</select>
</div>
</div>
</div>
</div>
</div>
</div>
#endif
</div>
<div class="col-lg-3">
#if(Cart::Count()>0)
<div class="card detail">
<div class="card-header">
</div>
<div class="card-body">
<p class="card-text" id="cart-summary">
Order Summary
</p>
<hr/>
<div class="row">
<div class="col-sm-6">
{{Cart::Count()}}
</div>
<div class="col-sm-6">
#if(Cart::Count()==1)
Item
#else
Items
#endif
</div>
</div>
<hr/>
<div class="row">
<div class="col-sm-6">
<p>
Subtotal
</p>
<p>
VAT (15%)
</p>
<p>
Total to Pay
</p>
</div>
<div class="col-sm-6" id="cart-totals">
<p>
R{{Cart::subtotal()}}
</p>
<p>
R{{Cart::tax()}}
</p>
<p>
R{{Cart::total()}}
</p>
</div>
</div>
<hr/>
<div class="row">
<div class="col-12 continue-btn">
Continue
</div>
</div>
{{-- <hr>
<div class="row" id="delivery-method">
<select class="form-control select2" id="delivery_method" name="del">
<option value="0" selected disabled>Select Delivery Method</option>
#foreach ($delivery_method as $item)
<option value="{{$item['delivery_method']}}">{{$item['delivery_method']}} R{{$item['price']}}</option>
#endforeach
</select>
</div> --}}
</div>
{{-- <div class="card-footer" id="cart-footer">
<div class="delivery_type">
<strong>Checkout</strong>
</div>
{{-- <div class="delivery_type2">
<strong>Checkout 2</strong>
</div> --}}
{{-- </div> --}}
</div>
<div class="card order-review">
<div class="card-body">
<p class="card-text" id="cart-summary">
Order Review
</p>
<div class="row">
<div class="col-sm-12">
<p><strong>Delivery Method</strong> <span class="change-del pull-right">Change</span></p>
<p>Delivery</p>
</div>
</div>
</div>
</div>
#endif
</div>
</div>
</div>
</div>
<!-- NewAddressModal -->
<!-- Modal -->
<div class="modal fade show" id="newAddressModal" style="display: none;" aria-modal="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Default Modal</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
#push('custom_scripts')
<script type="text/javascript">
$(document).ready(function() {
{{-- $("#newAddress").change(function() {
var curVal = $("#newAddress option:selected").val();
if (curVal.indexOf('#newAddressModal') == 0){
$('#newAddressModal').modal('show');
}
}); --}}
$("#newAddress").on("change", function () {
$modal = $('#newAddressModal');
if($(this).val() === '0'){
$modal.modal('show');
}
});
});
</script>
#endpush
#endsection
Error Image
Error Image
Try grouping Multiple collection into one array, Then send it to the view like this:
$viewData = [
'cartItems' => $cartItems,
'allcategories' => $allcategories,
'shippingaddress' => $shippingaddress
];
return View::make('shipping.index')->with($viewData);
Related
I have a food ordering web app in PHP laravel 5.8. The items modal is working fine with the following code but when I am trying to display the deals modal in the same manner, it does not work at all. I am sharing my blade files. The "show.blade.php" file displays the entire front page where these modals have to be shown to the customer. The "modal.blade.php" file is where the modals are defined and their data is coming from the "show.blade.php" page. The first div in the modals file is the one that I want to work and the second is the one that is currently working fine. You can ignore the last modal div.
show.blade.php
#extends('layouts.front', ['class' => ''])
<?php
use Carbon\Carbon;
use App\User;
$name = new User();
?>
#section('content')
#include('restorants.partials.modals')
<section class="section pt-lg-0" id="restaurant-content" style="padding-top: 0px">
<input type="hidden" id="rid" value="{{ $restorant->id }}" />
<div class="container container-restorant">
<hr>
#if ($deals)
<div class="owl-carousel owl-theme owl-loaded">
<div class="owl-stage-outer">
<div class="owl-stage">
<h1>Deals</h1>
#foreach ($deals as $deal)
<div class="col-xl-3 col-lg-6 col-md-6 col-sm-6">
<div class="owl-item">
<div id="addToCart1">
<div class="strip">
<figure style="border-radius: 3rem">
<a onClick="setCurrentDeal({{ $deal->id }})" href="javascript:void(0)"><img
src="{{ $deal->image_url }}_thumbnail.jpg" loading="lazy"
data-src="{{ config('global.restorant_details_image') }}"
class="img-fluid lazy" alt=""></a>
</figure>
<span class="res_title"><b><a onClick="setCurrentDeal({{ $deal->id }})"
href="javascript:void(0)">{{ $deal->name }}</a></b></span><br />
<span class="res_description">{{ $deal->description }}</span><br />
<div class="d-flex justify-content-between">
<div>
#php
$dealItems = [];
$dealItems = App\DealItem::where('deal_id', $deal->id)->get();
#endphp
#foreach ($dealItems as $it)
<h6><strong>{{ $it->item->name }}</strong></h6>
#endforeach
</div>
<h6 class="text-success"><strong>Price:{{ $deal->price }}</strong></h6>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="owl-dots">
<div class="owl-dot active"><span></span></div>
<div class="owl-dot"><span></span></div>
<div class="owl-dot"><span></span></div>
</div>
</div>
#endforeach
#endif
</div>
#section('js')
<script>
$(function() {
$('.owl-carousel').owlCarousel({
margin: 50,
autoplay: true,
loop: true
});
});
var deals = [];
var currentDeal = null;
var currentDealSelectedPrice = null;
var lastAdded = null;
var CASHIER_CURRENCY = "<?php echo env('CASHIER_CURRENCY', 'usd'); ?>";
var LOCALE = "<?php echo App::getLocale(); ?>";
/*
* Price formater
* #param {Nummber} price
*/
function formatPrice(price) {
var formatter = new Intl.NumberFormat(LOCALE, {
style: 'currency',
currency: CASHIER_CURRENCY,
});
var formated = formatter.format(price);
return formated;
}
function setCurrentDeal(id) {
var deal = deals[id];
currentDeal = deal;
$('#modalDealTitle').text(deal.name);
$('#modalDealName').text(deal.name);
$('#modalDealPrice').html(deal.price);
$('#modalDealID').text(deal.id);
$("#modalDealImg").attr("src", deal.image);
$('#modalDealDescription').html(deal.description);
//Normal
currentDealSelectedPrice = deal.priceNotFormated;
// $('#variants-area').hide();
$('.quantity-area').show();
$('#dealModal').modal('show');
}
<?php
$deals =[];
foreach ($deals as $deal){
$theArray = [
'name' => $deal->name,
'id' => $deal->id,
'priceNotFormated' => $deal->price,
'price' => #money($deal->price, env('CASHIER_CURRENCY', 'usd'), true) . '',
'image' => $deal->logom,
'description' => $deal->description,
];
echo 'deals[' . $deal->id . ']=' . json_encode($theArray) . ';';
}
?>
<script>
$(document).ready(function() {
$("#addToCart1").show();
// $('#exrtas-area').show();
$('.quantity-area').show();
});
</script>
#endsection
modals.blade.php
<div class="modal fade" id="dealModal" z-index="9999" tabindex="-1" role="dialog" aria-labelledby="modal-form" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered modal-" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 id="modalDealTitle" class="modal-title" id="modal-title-new-item"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body p-0">
<div class="card bg-secondary shadow border-0">
<div class="card-body px-lg-5 py-lg-5">
<div class="row">
<div class="col-sm col-md col-lg col-lg text-center">
<img id="modalDealImg" src="" width="295px" height="200px">
</div>
<div class="col-sm col-md col-lg col-lg">
<input id="modalDealID" type="hidden"></input>
<span id="modalDealPrice" class="new-price"></span>
<p id="modalDealDescription"></p>
</div>
<div class="offset-md-6 col-md-6">
#if(!config('app.isqrsaas'))
<div class="quantity-area">
<div class="form-group">
<br />
<label class="form-control-label" for="quantity">{{ __('Quantity') }}</label>
<input type="number" name="quantity" id="quantity" class="form-control form-control-alternative" placeholder="{{ __('1') }}" value="1" required autofocus>
</div>
<div class="quantity-btn float-right">
<div id="addToCart1">
<button class="btn btn-primary" v-on:click='addToCartAct'
<?php
if(auth()->user()){
if(auth()->user()->hasRole('client')) {echo "";} else {echo "disabled";}
}else if(auth()->guest()) {echo "";}
?>
>{{ __('Add To Cart') }}</button>
</div>
</div>
</div>
#endif
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="productModal" z-index="9999" tabindex="-1" role="dialog" aria-labelledby="modal-form" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered modal-" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 id="modalTitle" class="modal-title" id="modal-title-new-item"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body p-0">
<div class="card bg-secondary shadow border-0">
<div class="card-body px-lg-5 py-lg-5">
<div class="row">
<div class="col-sm col-md col-lg col-lg text-center">
<img id="modalImg" src="" width="295px" height="200px">
</div>
<div class="col-sm col-md col-lg col-lg">
<input id="modalID" type="hidden"></input>
<span id="modalPrice" class="new-price"></span>
<p id="modalDescription"></p>
<div id="variants-area">
<label class="form-control-label">{{ __('Select your options') }}</label>
<div id="variants-area-inside">
</div>
</div>
</div>
<div class="col-md-12">
<div id="exrtas-area">
<br />
<label class="form-control-label h4" for="quantity">{{ __('Extras') }}</label>
<div class="row" id="exrtas-area-inside"></div>
</div>
</div>
<div class="offset-md-6 col-md-6">
#if(!config('app.isqrsaas'))
<div class="quantity-area">
<div class="form-group">
<br />
<label class="form-control-label" for="quantity">{{ __('Quantity') }}</label>
<input type="number" name="quantity" id="quantity" class="form-control form-control-alternative" placeholder="{{ __('1') }}" value="1" required autofocus>
</div>
<div class="quantity-btn float-right">
<div id="addToCart1">
<button class="btn btn-primary" v-on:click='addToCartAct'
<?php
if(auth()->user()){
if(auth()->user()->hasRole('client')) {echo "";} else {echo "disabled";}
}else if(auth()->guest()) {echo "";}
?>
>{{ __('Add To Cart') }}</button>
</div>
</div>
</div>
#endif
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I want to get the .text() of the sibling customerID from the class"db_record_left" when class="db_record_left" gets clicked.
The whole class="db_record" is dynamical generated. But the console.log(CustID); still prints it for every class="db_record" and not only for the clicked one.
echo'
<div class="db_record" id="potentialCustomer-'.$countPotentialCustomers.'">
<div class="db_record_left">
<div class="db_record_describer">'.$cus_Fname.' '.$cus_Lname.'</div>
<div class="db_record_info_wrapper">
<div class="db_record_info_describer">Adresse:</div>
<div class="db_record_info">'.$cus_Adress.'</div>
<div class="db_record_info">
<span>'.$cus_ZipCode.' </span>
<span>'.$cus_Locality.'</span>
</div>
</div>
<div class="db_record_info_wrapper">
<div class="db_record_info_describer">Fahrzeuge:</div>
'.matchVehicles($cus_Vehicles).'
</div>
</div>
<div class="db_record_right">
<div class="material-icons md-large md-ghost-white-enabeld w-embed">
<span class="material-icons-outlined">navigate_next</span>
</div>
</div>
</div>
<span class="customerID" style="display: none">'.$cus_ID.'</span>
';
This would be the jQuery-code
function checkCustomerInformation(){
$(".db_records_wrapper").on('click', 'div.db_record', function (){
const CustID = $(this).siblings(".customerID").text();
console.log(CustID);
});
}
siblings() gets every matching sibling element. To get only the only following the .db_record which was clicked, use next():
$(this).next(".customerID").text();
Here's a working example:
function checkCustomerInformation() {
$(".db_records_wrapper").on('click', 'div.db_record', function() {
const custID = $(this).next(".customerID").text();
console.log(custID );
});
}
checkCustomerInformation();
.db_record {
margin: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div class="db_records_wrapper">
<div class="db_record" id="potentialCustomer-'.$countPotentialCustomers.'">
<div class="db_record_left">
<div class="db_record_describer">$cus_Fname1 $cus_Lname1</div>
<div class="db_record_info_wrapper">
<div class="db_record_info_describer">Adresse:</div>
<div class="db_record_info">$cus_Adress1</div>
<div class="db_record_info">
<span>$cus_ZipCode1</span>
<span>$cus_Locality1</span>
</div>
</div>
<div class="db_record_info_wrapper">
<div class="db_record_info_describer">Fahrzeuge:</div>
matchVehicles($cus_Vehicles1)
</div>
</div>
<div class="db_record_right">
<div class="material-icons md-large md-ghost-white-enabeld w-embed">
<span class="material-icons-outlined">navigate_next</span>
</div>
</div>
</div>
<span class="customerID" style="display: none">$cus_ID1</span>
<div class="db_record" id="potentialCustomer-'.$countPotentialCustomers.'">
<div class="db_record_left">
<div class="db_record_describer">$cus_Fname2 $cus_Lname2</div>
<div class="db_record_info_wrapper">
<div class="db_record_info_describer">Adresse:</div>
<div class="db_record_info">$cus_Adress2</div>
<div class="db_record_info">
<span>$cus_ZipCode2</span>
<span>$cus_Locality2</span>
</div>
</div>
<div class="db_record_info_wrapper">
<div class="db_record_info_describer">Fahrzeuge:</div>
matchVehicles($cus_Vehicles2)
</div>
</div>
<div class="db_record_right">
<div class="material-icons md-large md-ghost-white-enabeld w-embed">
<span class="material-icons-outlined">navigate_next</span>
</div>
</div>
</div>
<span class="customerID" style="display: none">$cus_ID2</span>
</div>
In an html page, I would like to recover the value of an amount and can change the value only in my admin panel.
In the file navbar.blade.php I have 250 which is the amount to edit for the example.
<div class="header-widgets hidden-xs" style="padding:0px;padding-top: 60px;">
<div id="text-3" class="widget widget_text">
<div class="textwidget">
<div class="info-icon">
<img src="/img/time.png">
<span style="font-size: 22px;color: #0d3863;font-weight: bold;"> 250</span>
</div>
</div>
</div>
</div>
I just seek to edit the amount (250) ...
In my Controller named tarrifcontroller I have that.
public function edit(Tariff $tariff)
{
return view('admin.tariffs.edit', compact('tariff'));
}
public function update(Request $request, Tariff $tariff)
{
$tariff->valeur = strip_tags($request->input('amount'));
$tariff->save();
return redirect('/tariffs');
}
In my edit.blade.php I have that
#section('content')
<div class="px-content">
<div class="page-header">
<div class="row">
<div class="col-md-4 text-xs-center text-md-left text-nowrap">
<h1><i class="px-nav-icon ion-android-apps"></i>Tarif {{$tariff->id}} </h1>
</div>
<hr class="page-wide-block visible-xs visible-sm">
<!-- Spacer -->
<div class="m-b-2 visible-xs visible-sm clearfix"></div>
</div>
</div>
<div class="row">
<div class="panel">
<div class="panel-body">
<div class="table-responsive">
<form class="panel-body" action="/tariff/edit/{{$tariff->id}}" method="POST">
#csrf
<fieldset class="form-group">
<label for="form-group-input-1">Amount</label>
<input type="text" name="amount" class="form-control" id="form-group-input-1" value="{{$tariff->amount}}">
</fieldset>
<button type="submit" class="btn btn-primary pull-right">MAJ</button>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
My problem is now in navbar.blade.php how should I do that 250 can interact with my edit / update function?
<span style="font-size: 22px;color: #0d3863;font-weight: bold;"> 250</span>
Thank you
I don't have experience with laravel but i guess like any other php framework you can echo variable from controller to view
<span style="font-size: 22px;color: #0d3863;font-weight: bold;"> <?php echo $variable ?></span>
after some googling: You can pass data to the view using the with method.
return View::make('blog')->with('posts', $posts);
I can't open my modal in CodeIgniter.
I did a view for the modal and then I loaded in the controller. But when I click on the button, it doesn't show anything. No response. head have the Jquery and Bootstrap imports in the correct order.
Here i show you my code:
cdashboard.php:
//header
$this->load->view('UI/vheader');
//sidebar
$this->load->view('UI/vsidebar',$data);
//modals
$data['modaltarea'] = $this->load->view('tareas/vmodalnewtarea',NULL,TRUE);
//data in dashboard
$this->load->view('vdashboard',$data);
//footer
$this->load->view('UI/vfooter');
vmodalnewtarea.php:
<div id="newTareaModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="newTarea" aria-hidden="true">
<div class="modal-dialog" >
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Tarea nueva</h5>
</div>
<div class="modal-body">
<div class="container-fluid">
<!--Importar plantilla-->
<div class="row">
<div class="col-md-12">
<h3>Importar plantilla</h3>
</div>
<div class="row">
<!--Proyecto-->
<div class="col-md-4">
</div>
<!--Fase-->
<div class="col-md-4">
</div>
<!--Tarea-->
<div class="col-md-4">
</div>
</div>
</div>
<!--Nueva Fase-->
<div class="row">
<div class="col-md-12">
<h3>Nueva Tarea</h3>
</div>
<div class="row">
<div class="col-md-4">
<div class="row">
<input type="text" placeholder="Nombre" required />
</div>
<div class="row">
<!--<table id="tableHitos" class="table table-bordered table-strip" >
<thead>
<th>
Hitos
</th>
</thead>
<tbody>
</tbody>
</table>-->
<a type="button" class="btn"><i class="fa fa-plus"></i></a>
</div>
</div>
<div class="col-md-8">
<textarea id="txtaTarea" rows="5" placeholder="Descripcion" required>
</textarea>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<p>
aaaaaa
</p>
</div>
</div>
</div>
</div>
And the view where I call the modal, on other view (vrowfase.php):
<div class="row fase">
<div class="col-lg-12">
<div class="col-lg-2 text-center">
<div class="callout callout-warning">
<h4><?= $fase->nombre?></h4>
<div class="progress progress-xxs">
<div class="progress-bar" role="progressbar" style="width: 50%">
</div>
</div>
</div>
</div>
<div class="projectBar col-lg-10">
<div class="row Bar">
<?= $tareas; ?>
<button type="button" class="btn btn-app text-center" data-toogle="modal" data-target="#newTareaModal">
<i class="fa fa-plus"></i>
Nueva Tarea
</button>
</div>
</div>
</div>
</div>
thanks for the help!
your modal id is
newTareaModal
and your data-target in button is
TareaModal
was a error writing.
on vrowfase.php I had "data-toogle" and is "data-toggle"
thank you anyway!
I am working on laravel 5.2.I want to display those members who belongs to that particular group which is open at this time. Actually, i am getting all the members which i have stored in my database but, i only want to access or display only those members who belongs to a particular on which i am currently accessing.
I am getting an error: Method groups does not exist. which is shown below:
My controller:
public function members($id){
$dashes=Grouptable::findorFail($id);
$members=Member::all();
return view('members' , ['dashes'=>$dashes,'members'=>$members]);
}
public function dashboard($id){
$dashes=Grouptable::findorFail($id);
return view('dashboard' , ['dashes'=>$dashes]);
}
public function addmembers(Request $request){
$member=new Member();
$member->members=$request['addmember'];
$request->groups()->members()->save($member);
return redirect()->back();
}
My view:
<body>
<div class="row">
<div class="col-lg-3 col-lg-offset-1">
<img src="images/ImgResponsive_Placeholder.png"
class="img-circle img- responsive" alt="Placeholder image"> </div>
<div class="col-lg-7">
<h1 style="color:black;">{{ $dashes->name }}</h1></div>
<br />
</div>
<div class="row">
<div class="col-lg-3">
<button class="btn btn-success" onclick="myFunction()">
Add Members + </button>
<div>
<form id="demo" style="display:none;" method="post"
action="{{ route('addmember') }}">
<input class="form-control" type="text" name="addmember">
<button class="btn btn-primary" type="submit">Add</button>
<input type="hidden" name="_token" value="{{ Session::token() }}">
</form>
</div>
</div>
<div class="col-lg-7 col-lg-offset-0">
<div class="panel panel-default">
<div id="grp" class="panel-heading">
<h3 id="grouptitle" class="panel-title">Group Members</h3>
</div>
<div id="zx" class="panel-content">
<div class="row">
#foreach($members as $member)
<section class="col-md-6">
<div class="row">
<section class="col-md-offset-1 col-md-3 col-xs-offset-1 col-xs-4">
<img id="imagesize" src="images/g.jpg" class="img-circle"/>
</section>
<section class="col-md-offset-1 col-md-7 col-xs-7">
<section class="col-md-12">
<h5 id="friendname">{{$member->members}}</h5>
</section>
<section class="col-md-12">
<button type="button" class="btn btn-sm btn-
default">Score</button>
</section>
</section>
</div>
<div class="row">
<section class="col-md-offset-9 col-md-3 col-xs-offset-6
col-xs-4">
<div class="btn-group">
<button id="btnclr1" type="button" class="btn btn-block
btn-warning dropdown-toggle" data-toggle="dropdown" aria-
expanded="false"><span class="caret"></span></button>
<ul id="bckdrp" class="dropdown-menu" role="menu">
<li role="presentation"><a id="drpmenu" href="#">Remove</a>
</li>
</ul>
</div>
</section>
</div>
<div class="row">
<section class="col-md-offset-1 col-md-10">
<hr>
</section>
</section>
#endforeach
</div>
<div id="mn" class="panel-footer"><a id="seemr1"
href="#.html">See More</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
My routes:
Route::get('/members/{id}',[
'uses'=>'GroupController#members',
'as'=>'members'
]);
Route::get('/dashboard/{id}',[
'uses'=>'GroupController#dashboard',
'as'=>'dashboard'
]);
Route::post('/memeber/add',[
'uses'=>'GroupController#addmembers',
'as'=>'addmember'
]);
My modals:
Grouptable:
public function members(){
return $this->hasMany('App\Member');
}
Member:
public function groups(){
return $this->belongsTo('App\Grouptable');
}
I do not quite understand the entire problem, but
public function addmembers(Request $request){
$member=new Member();
$member->members=$request['addmember'];
$request->groups()->members()->save($member);
return redirect()->back();
}
should look more like
public function addmembers(Request $request){
$member=new Member();
$member->propertyX = $request->get('propertyX');
$member->propertyY = $request->get('propertyY');
$member->groups()->attach($group); // FOR MANY-TO-MANY (N-N) RELATION
$member->groups()->associate($group); // FOR ONE-TO-MANY (1-N) RELATION
$member->save();
return redirect()->back();
}
Depending on your migrations you should choose attach() or associate()