Undefined offset: 1 in laravel 8 - php

Im currently learning to do sign in and sign up in laravel8 by referring some tutorials. But after sign up im getting this Undefined offset: 1 message.
Error line that showing is
$iteratee = trim($matches[1]);
This is my route file(web.php)
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
Route::get('/signup',[
'uses' =>'App\Http\Controllers\UserController#getSignup',
'as'=>'user.signup'
]);
Route::post('/signup',[
'uses' =>'App\Http\Controllers\UserController#getSignup',
'as'=>'user.signup'
]);
And this is the signup page register part
<header class="masthead" >
<div class="container">
<div class="masthead-subheading"></div>
<div class="masthead-heading text-uppercase"></div>
<div class="container">
<div class="card bg-light">
<article class="card-body mx-auto" style="max-width: 400px;">
<h4 class="card-title mt-3 text-center">Create Account</h4>
<p class="text-center">Get started with your free account</p>
#if(count($errors) > 0)
<div class="alert alert-danger">
#foreach($errors->all()as $error)
<p>{{$error}}</p>
#endforeach
</div>
#endif
<form action="{{ route('user.signup')}}">
<div class="form-group input-group">
<div class="input-group-prepend">
<span class="input-group-text"> <i class="fa fa-envelope"></i> </span>
</div>
<input name="email" class="form-control" placeholder="Email address" type="email">
</div>
<div class="form-group input-group">
<div class="input-group-prepend">
<span class="input-group-text"> <i class="fa fa-lock"></i> </span>
</div>
<input name="password" placeholder="Create password" type="password">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block"> Create Account </button>
{{csrf_field()}}
</div> <!-- form-group// -->
<p class="text-center">Have an account? Log In </p>
</form>
</article>
</div> <!-- card.// -->
</div>
<!--container end.//-->
</header>
UserController
class UserController extends Controller
{
public function getSignup()
{
return view('user.signup');
}
public function postSignup(Request $request)
{
$this->validate($request,[
'email'=> 'email|required|unique:users',
'password'=>'required|min:4'
]);
$user= new User([
'email'=>$request-> input('email'),
'password'=> bcrypt($request-> input('password'))
]);
$user-->save();
return redirect()->route('shop.index');
}
}
Please teach me a way to solve this.Thank you

You should add a space in the #foreach between the pieces:
#foreach($errors->all()as $error)
Should be:
#foreach($errors->all() as $error)
The Blade compiler parses the expression passed to this directive and does a preg_match on it to get the pieces of the expression as this directive does more than just creating a foreach loop. Here is the match on the expression:
preg_match('/\( *(.*) +as *(.*)\)$/is', $expression, $matches);
$iteratee = trim($matches[1]);

Related

How to to solve the problemThe POST method is not supported for this route. Supported methods: GET, HEAD

I want to create CRUD on admin dashboard, but But when i click submit button, i got this error message "POST method is not supported for this route. Supported method: GET, HEAD."
My View
#extends('layouts.admin')
#section('content')
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h3>Add Products
BACK
</h3>
</div>
<div class="card-body">
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form action="{{ url('admin/products') }}" method="POST" enctype="multipart/form-data">
#csrf
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="home-tab" data-bs-toggle="tab"
data-bs-target="#home-tab-pane" type="button" role="tab"
aria-controls="home-tab-pane" aria-selected="true">Home</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="seotag-tab" data-bs-toggle="tab"
data-bs-target="#seotag-tab-pane" type="button" role="tab"
aria-controls="seotag-tab-pane" aria-selected="false">SEO
Tags</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="details-tab" data-bs-toggle="tab"
data-bs-target="#details-tab-pane" type="button" role="tab"
aria-controls="details-tab-pane" aria-selected="false">Details</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="image-tab" data-bs-toggle="tab"
data-bs-target="#image-tab-pane" type="button" role="tab"
aria-controls="image-tab-pane" aria-selected="false">Product Image</button>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade border p-3 show active" id="home-tab-pane" role="tabpanel"
aria-labelledby="home-tab" tabindex="0">
<div class="md-3">
<label>Product Name</label>
<input type="text" name="name" class="form-control">
</div>
<div class="md-3">
<label>Product Slug</label>
<input type="text" name="name" class="form-control">
</div>
<div class="md-3">
<label>Small Description (500 Words)</label>
<textarea name="small_description" class="form-control" rows="4"></textarea>
</div>
<div class="md-3">
<label>Description</label>
<textarea name="description" class="form-control" rows="4"></textarea>
</div>
</div>
<div class="tab-pane fade border p-3" id="seotag-tab-pane" role="tabpanel"
aria-labelledby="profile-tab" tabindex="0">
<div class="md-3">
<label>Meta Title</label>
<input type="text" name="meta_title" class="form-control">
</div>
<div class="md-3">
<label>Meta Description</label>
<textarea name="small_description" class="form-control" rows="4"></textarea>
</div>
<div class="md-3">
<label>Meta Keyword</label>
<textarea name="meta_keyword" class="form-control" rows="4"></textarea>
</div>
</div>
<div class="tab-pane fade border p-3" id="details-tab-pane" role="tabpanel"
aria-labelledby="details-tab" tabindex="0">
<div class="row">
<div class="col-md-4">
<div class="md-3">
<label>Original Price</label>
<input type="text" name="original_price" class="form-control">
</div>
</div>
<div class="col-md-4">
<div class="md-3">
<label>Selling Price</label>
<input type="text" name="selling_price" class="form-control">
</div>
</div>
<div class="col-md-4">
<div class="md-3">
<label>Quantity</label>
<input type="number" name="quantity" class="form-control">
</div>
</div>
<div class="col-md-4">
<div class="md-3">
<label>Trending</label>
<input type="checkbox" name="trending" style="width: 50px; height; 50px;" />
</div>
</div>
<div class="col-md-4">
<div class="md-3">
<label>Status</label>
<input type="checkbox" name="status" style="width: 50px; height; 50px;" />
</div>
</div>
</div>
</div>
<div class="tab-pane fade border p-3" id="image-tab-pane" role="tabpanel"
aria-labelledby="image-tab" tabindex="0">
<div class="mb-3">
<label>Upload Product Images</label>
<input type="file" name="image" multiple class="form-control" />
</div>
</div>
</div>
</div>
<div>
<button type="submit" class="btn btn-primary text-white">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
#endsection
Controller
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\ProductFormRequest;
use App\Models\Product;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class ProductController extends Controller
{
public function index()
{
$product = Product::latest()->paginate(5);
return view('admin.products.index');
}
public function create()
{
return view('admin.products.create');
}
public function store(Request $request)
{
$this->validate($request, [
'name' => 'require|string|min:5',
'slug' => 'require|string|min:5',
'small_description' => 'require|string',
'description' => 'require|string',
'original_price' => 'require|integer',
'selling_price' => 'require|integer',
// 'trending' => 'nullable',
// 'status' => 'nullable',
'meta_title' => 'require|string|max:255',
'meta_keyword' => 'require|string',
'meta_description' => 'require|string',
'image' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048'
]);
// upload new image
$image = $request->file('image');
$image->storeAs('admin/products', $image->hashName());
Product::create([
'name' => $request->name,
'slug' => $request->slug,
'small_description' => $request->small_description,
'description' => $request->description,
'original_price' => $request->original_price,
'selling_price' => $request->selling_price,
'meta_title' => $request->meta_title,
'meta_keyword' => $request->meta_keyword,
'meta_description' => $request->meta_description,
'image' => $image->hashName()
]);
//redirect to index
return redirect()->route('admin.products.index')->with(['success' => 'Data Berhasil Disimpan!']);
}
}
My Route
Route::controller(App\Http\Controllers\Admin\ProductController::class)->group(function (){
Route::get('/products','index');
Route::get('/products/create','create');
Route::post('/admin/products','store');
});
I want to submit. But when I click on submit button, I got this error message "The POST method is not supported for this route. Supported methods: GET, HEAD."
enter image description here
Your code looks fine to me.
I had the same error also, try clearing the route cache and hopefully that will solve your problem.
Command:
php artisan route:cache

Laravel 7: User Profile causing bug when uploading img and bio description

In a laravel 7 app I'm working on a feature where a user can upload their image profile and bio description. A problem that I'm facing is that there are certain cases when a user sets their profile image, the bio description would be gone. For example: If a user set their profile img and puts a description, but if the user sets another img then the description would be gone. Not quite sure what's the bugs that's causing it. (I'm using bootstrap modal for the user to edit their profile.)
controller.php
public function modalEditPost(Request $request)
{
$user = Auth::user();
$avatarName = "";
$userBio = "";
$request->validate([
'bio' => 'nullable|string|max:255',
'image' => 'mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
if ($request->has('bio')) {
$userBio = $request->bio;
$user->bio = $userBio;
}
if ($request->hasFile('image')) {
if ($request->file('image')->isValid()) {
$extension = $request->image->extension();
$avatarName = $user->id.'_avatar'.time().'.'.$extension;
$request->image->move(public_path('/uploads/avatars'), $avatarName);
$user->avatar = $avatarName;
}
}
$user->save();
return back()
->with('success','You have successfully edited your bio.')
->with('bio', $userBio)
->with('image', $avatarName);
}
index.blade.php
#include('partials.popup')
<div class="col-md-4">
<div class="card card-user">
<div class="card-body">
<p class="card-text">
<div class="author">
<div class="block block-one"></div>
<div class="block block-two"></div>
<div class="block block-three"></div>
<div class="block block-four"></div>
<img class = "avatar" src="/uploads/avatars/{{ Auth::user()->avatar}}" alt="">
<h4 class="title">{{ auth()->user()->first_name }} {{ auth()->user()->last_name }}</h5>
</div>
<div class="card-description">
{{ Auth::user()->bio }}
</div>
<br>
<div class="text-center">
<button class="btn btn-success"
style="cursor: pointer"
data-toggle="modal"
data-target="#popupModal">{{ __('Edit Profile') }}
</button>
</div>
</div>
</div>
popup.blade.php
<div class="modal-body">
<!-- (Image upload) Start -->
#if ($message = Session::get('success'))
<div class="alert alert-success alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
</div>
#endif
#if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<!-- (Image upload) Start -->
<form action="{{ route('modal.upload.post') }}" method="POST" enctype="multipart/form-data">
#csrf
<div class="row">
<div class="col-md-6">
<input type="file" name="image" class="form-control-file">
</div>
</div>
<br>
<div class="row">
<div class="col">
<p>Change Bio</p>
</div>
</div>
<div class="row">
<div class="col">
<input type="text" style="color:black" name="bio" class="form-control">
</div>
</div>
<br>
<div class="col-md-6">
<button type="submit" class="btn btn-success">Update</button>
</div>
</form>
<!-- (Image upload) End -->
</div>

Having 2 forms on the same page in Laravel?

I'm trying to tackle a "two forms on one page" issue with my PHP code, but its turning out to be more tirkcy than I expected, and just isn't behaving in the correct way as I thought it would.
For the first form (Login) I'm using this if statement to determine if the message if for the Login.
#if(Session::has('message') && Session::get('last_message_for') == 'login')
<div class="notification is-{{ Session::get('color') }}">
<i class="fa fa-times"></i> {{ Session::get('message') }}
</div>
#elseif($errors->first() && Session::get('last_message_for') == 'login')
<div class="notification is-warning">
<i class="fa fa-times"></i> {{ $errors->first() }}
</div>
#endif
I've got the same code for my second form, but it just checks the last_message_for for a different value to 'login'.
#if(Session::has('message') && Session::get('last_message_for') == 'modal')
<div class="modal is-active" id="modal-forgotPassword">
#else
<div class="modal" id="modal-forgotPassword">
#endif
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title" id="open-modal">Forgot Password?</p> <button class="delete"></button>
</header>
<form action="{{ route('frontend.guest.password.forgot') }}" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<section class="modal-card-body">
<div class="content">
#if(Session::has('message') && Session::get('last_message_for') == 'modal')
<div class="notification is-{{ Session::get('color') }}">
<i class="fa fa-times"></i> {{ Session::get('message') }}
</div>
#endif
<div class="field">
<p class="control has-icons-left">
<input class="input" name="email" placeholder="Enter an email..." type="email">
<span class="icon is-small is-left"><i class="fa fa-envelope"></i></span>
</p>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</div>
</section>
<footer class="modal-card-foot">
<button class="button is-success" type="submit"><i class="fa fa-sign-in"></i> Send email</button>
</footer>
</form>
</div>
</div>
Now down to the issue, the Login part works perfectly fine and shows the error messages when there are any for it, but the second one isn't showing any errors when I have some.
I'm using this to set the last_message_for
Session::put('last_message_for', 'login');
Here is the code for my second form:
public function onForgotPassword(Request $request) {
$validator = Validator::make($request->all(), [
'email' => 'required|email|exists:users,mail',
]);
Session::put('last_message_for', 'modal');
if ( $validator->fails()) {
return redirect()->route('frontend.guest.login')->withErrors($validator->messages());;
}
else {
Mail::to($request->input('email'))->send(new ForgotPasswordEmail());
return redirect()->route('frontend.guest.login')->withMessage('Email Sent')->withColor('warning');
}
}
You're not handling validation errors, only the messages returned, this should do it.
#if(Session::has('message') && Session::get('last_message_for') == 'modal')
<div class="notification is-{{ Session::get('color') }}">
<i class="fa fa-times"></i> {{ Session::get('message') }}
</div>
#elseif($errors->first() && Session::get('last_message_for') == 'login')
<div class="notification is-warning">
<i class="fa fa-times"></i> {{ $errors->first() }}
</div>
#endif
I have two forms in the same page so you can easily assign it error to each form using flash session
in your controller just use session like this line
use Session;
this code related to two search forms
//searchInHistory
public function searchInHistory(){
$date = Request()->all();
$rules = [
'dateFrom' =>'required',
'dateTo' =>'required',
];
$validator = Validator($date,$rules);
if ($validator->fails()){
Session::flash('inError', 'inError');
return redirect()
->back()
->withErrors($validator)
->withInput();
}else{
$store = DB::table('stores')->select(
'store_details.id',
'store_details.status',
'stores.id AS storeId',
'stores.partNo',
'stores.title',
'store_details.serialNo',
'store_details.created_at',
'store_details.updated_at'
)
->join('store_details', 'store_details.storeId', '=', 'stores.id')
->where('store_details.status','inside')
->whereBetween('store_details.created_at',[$date['dateFrom'],$date['dateTo']])
->get();
return view('crm.store.in',compact('store'));
}
}
//===============
//searchHistory
public function searchOutHistory(){
$date = Request()->all();
$rules = [
'dateFrom' =>'required',
'dateTo' =>'required',
];
$validator = Validator($date,$rules);
if ($validator->fails()){
Session::flash('inError', 'inError');
return redirect()
->back()
->withErrors($validator)
->withInput();
}else{
$store = DB::table('stores')->select(
'store_details.id',
'store_details.status',
'stores.id AS storeId',
'stores.partNo',
'stores.title',
'store_details.serialNo',
'store_details.created_at',
'store_details.updated_at'
)
->join('store_details', 'store_details.storeId', '=', 'stores.id')
->where('store_details.status','outside')
->whereBetween('store_details.updated_at',[$date['dateFrom'],$date['dateTo']])
->get();
return view('crm.store.out',compact('store'));
}
}
//===============
the following code above each error assigned to specific form using session
this is blade code view code related to two form
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-header">
<h3 class="box-title">Store IN / OUT Control</h3>
</div>
<div class="row">
<div class="col-md-6">
<div class="box-body">
#if(session('outError'))
#if ($errors->any())
<div class="alert alert-danger">
<center>
#foreach ($errors->all() as $error)
{{ $error }}<br>
#endforeach
</center>
</div>
#endif
#endif
#if(session('out'))
#if(session('save'))
<div class="alert alert-success">
<center>
Products Came out of Successfully
</center>
</div>
#endif
#endif
<!-- form start -->
<form role="form" method="post" action="{{url('admin/takeProductOutStore')}}" enctype="multipart/form-data">
{{csrf_field()}}
<div class="box-body">
<input type="hidden" name="id" value="{{$storeId}}">
<div class="form-group">
<label>Products in Store</label>
<select multiple class="form-control" name="products[]" required>
#foreach($InDoorProducts as $row)
<option value="{{$row->serialNo}}">{{$row->serialNo}}</option>
#endforeach
</select>
</div>
<div class="form-group">
<label>Date</label>
<input type="date" class="form-control" name="date" required>
</div>
<div class="form-group">
<textarea class="textarea" required placeholder=" Write Notes"style="width: 100%; height: 125px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;" name="note" value="{{old('note')}}"></textarea>
</div>
</div><!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary">Out Store <b>→</b></button>
</div>
</form>
</div>
</div>
<div class="col-md-6">
<div class="box-body">
#if(session('inError'))
#if ($errors->any())
<div class="alert alert-danger">
<center>
#foreach ($errors->all() as $error)
{{ $error }}<br>
#endforeach
</center>
</div>
#endif
#endif
#if(session('in'))
#if(session('save'))
<div class="alert alert-success">
<center>
Products Added to Store Again Successfully
</center>
</div>
#endif
#endif
<!-- form start -->
<form role="form" method="post" action="{{url('admin/takeProductInStore')}}" enctype="multipart/form-data">
{{csrf_field()}}
<div class="box-body">
<input type="hidden" name="id" value="{{$storeId}}">
<div class="form-group">
<label>Products Out Store</label>
<select multiple class="form-control" name="products[]" required>
#foreach($OutDoorProducts as $row)
<option>{{$row->serialNo}}</option>
#endforeach
</select>
</div>
<div class="form-group">
<label>Date</label>
<input type="date" class="form-control" name="date" required>
</div>
<div class="form-group">
<textarea class="textarea" required placeholder=" Write Notes"style="width: 100%; height: 125px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;" name="note" value="{{old('note')}}"></textarea>
</div>
</div><!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary">Back To Store <b>←</b></button>
</div>
</form>
</div>
</div>
</div>
</section>

Method [vlidate] does not exist error in laravel 5.3 while trying to upload image

I am developing a project in laravel 5.3 where I have to create a 1 feild form to change logo of website my form look like this.
I do not need to save path in database. I just need to upload file in \public\images\ with name logo and only png files are allowed. so it will be \public\images\logo.png
following is the form code.
<div class="col-md-8 col-md-offset-2">
#if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
#if ($message = Session::get('success'))
<div class="alert alert-success alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
</div>
<img src="/images/{{ Session::get('path') }}">
#endif
<div class="box box-info">
<div class="box-header with-border text-center">
<h3 class="box-title">Basic Info</h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form class="form-horizontal" action="{{ url('/') }}/admin/change-site-logo" enctype="multipart/form-data" method="POST">
<div class="box-body">
{{ csrf_field() }}
<div class="form-group">
<label for="logo" class="col-sm-3 control-label">Logo</label>
<div class="col-sm-9">
<input type="file" class="form-control" id="logo" name="logo" placeholder="Logo Image">
</div>
</div>
<div class="form-group">
<label for="logo" class="col-sm-3 control-label"></label>
<div class="col-sm-9">
<img style="width: 200px; height: 50px;" src="https://www.google.com.pk/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png">
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-info pull-right">Save</button>
</div>
<!-- /.box-footer -->
</form>
</div>
<br /><br />
</div>
this is Route Route::post('/admin/change-site-logo', 'adminController#logo_change');
and controller is as following
class adminController extends Controller
{
public function logo_change(Request $request)
{
$this->vlidate($request, [
'logo' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$imageName = 'logo.'.$request->image->getClientOriginalExtension();
$request->image->move(public_path('images'), $imageName);
return back()
->with('success', 'Image Uploaded Successfully.')
->with('in path', $imageName);
}
I am writing first time this kind of code so dont know what to fix. I just know that the error is Method [vlidate] does not exist.

Method groups does not exist error in Laravel 5.2

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()

Categories