picture not displaying laravel 8 - image

This is my code
AdminAddProductComponent.php
<?php
namespace App\Http\Livewire\Admin;
use App\Models\Category;
use Livewire\Component;
use Illuminate\Support\Str;
use App\Models\Product;
use Livewire\WithFileUploads;
use Carbon\Carbon;
class AdminAddProductComponent extends Component
{
use WithFileUploads;
public $name;
public $slug;
public $short_description;
public $description;
public $regular_price;
public $sale_price;
public $SKU;
public $stock_status;
public $featured;
public $quantity;
public $image;
public $category_id;
public function mount()
{
$this->stock_status = 'instock';
$this->featured = 0;
}
public function generateSlug()
{
$this->slug = Str::slug($this->name,'-');
}
public function addProduct()
{
$product = new Product();
$product->name = $this->name;
$product->slug = $this->slug;
$product->short_description = $this->short_description;
$product->description = $this->description;
$product->regular_price = $this->regular_price;
$product->sale_price = $this->sale_price;
$product->SKU = $this->SKU;
$product->stock_status = $this->stock_status;
$product->featured = $this->featured;
$product->quantity = $this->quantity;
$imageName = Carbon::now()->timestamp.'.'.$this->image->extension();
$this->image->storeAs('products',$imageName);
$product->image = $imageName;
$product->category_id = $this->category_id;
$product->save();
session()->flash('message','Product has been created successfully!');
}
public function render()
{
$categories=Category::all();
return view('livewire.admin.admin-add-product-component',['categories'=>$categories])->layout('layouts.base');
}
}
admin-add-product-component.blade.php
<div>
<div class="container"style="padding:30px 0;">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<div class="row">
<div class="col-md-6">
Add New Product
</div>
<div class="col-md-6">
All Products
</div>
</div>
</div>
<div class="panel-body">
#if(Session::has('message'))
<div class="alert alert-success" role="alert">{{Session::get('message')}}</div>
#endif
<form class="form-horizontal" enctype="multipart/form-data"wire:submit.prevent="addProduct">
<div class="form-group">
<label class="col-md-4 control-label">Product Name</label>
<div class="col-md-4">
<input type="text" placeholder="Product Name" class="form-control input-md"wire:model="name"wire:keyup="generateSlug"/>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Product Slug</label>
<div class="col-md-4">
<input type="text" placeholder="Product Slug" class="form-control input-md"wire:model="slug"/>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Short Description</label>
<div class="col-md-4">
<textarea class="form-control" placeholder="Short Description"wire:model="short_description"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Description</label>
<div class="col-md-4">
<textarea class="form-control" placeholder="Description"wire:model="description"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Regular Price</label>
<div class="col-md-4">
<input type="text" placeholder="Regular Price" class="form-control input-md"wire:model="regular_price"/>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Sale Price</label>
<div class="col-md-4">
<input type="text" placeholder="Sale Price" class="form-control input-md"wire:model="sale_price"/>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">SKU</label>
<div class="col-md-4">
<input type="text" placeholder="SKU" class="form-control input-md"wire:model="SKU"/>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Stock</label>
<div class="col-md-4">
<select class="form-control"wire:model="stock_status">
<option value="instock">InStock</option>
<option value="outofstock">Out of Stock</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Featured</label>
<div class="col-md-4">
<select class="form-control"wire:model="featured">
<option value="0">No</option>
<option value="1">Yes</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Quantity</label>
<div class="col-md-4">
<input type="text" placeholder="Quantity" class="form-control input-md"wire:model="quantity"/>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Product image</label>
<div class="col-md-4">
<input type="file" class="input-file"wire:model="image"/>
#if($image)
<img src="{{$image->temporaryUrl()}}"width="120"/>
#endif
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Category</label>
<div class="col-md-4">
<select class="form-control"wire:model="category_id">
<option value="">Select Category</option>
#foreach ($categories as $category)
<option value="{{$category->id}}">{{$category->name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label"></label>
<div class="col-md-4">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
I don't know why it's not working.. I mean the picture cant display on my Image show product page...
https://www.youtube.com/watch?v=IcGAM05UMwA&list=PLz_YkiqIHesvPtvLl2Wz5FtuW44dBt199&index=18&ab_channel=SurfsideMedia I follow this video<<< it just I dont know why my picture not showing out. it show the alt="picture" things

add use Livewire\Carbon; instead of usu carbo

Related

how to fix,"Call to a member function row() on null "

How to fix
Call to a member function row() on null
THIS IS MY CONTROLLER
function forwardtrack($param='',$param2='') {
if(sizeof($this->db->get_where('st_forward',array('letter_no' =>$param.'/'.$param2))->result_array())>0 && (!($param.'/'.$param2) )){
$data1['message']= 'notallow';
$this->load->view('track1',$data1);
}
else{
$data1['name']=$this->db->get_where('bpas_user_profiles',array('AgencyMainParentID' =>$this->session->userdata('ministryId'),'AgencyParentID'=>$this->session->userdata('parentID'),'AgencyID'=>$this->session->userdata('agencyID')))->result_array();
$data1['userdeatils']=$this->ag->tracks($param.'/'.$param2);
$this->load->view('userManagement/forward2', $data1);
}
/* ag=> agency model */
}
THIS IS MY MODEL
public function tracks($letterno="")
{
$query= $this->db->get_where('st_dak_details',array('dakLetterNo'=>$letterno))->row();
return $query;
}
THIS VIEW PAGE
<br/>
<div class="container">
<div class="panel panel-info">
<div class="panel-heading">
<i class="fa fa-envelope-o fa-fw"></i>forward to
</div>
<div class="panel-body">
<form class="form-horizontal" enctype="multipart/form-data" action="#" method="post" id="forwardmessage">
<div class="form-group">
<label for="letter"class="col-xs-12 col-lg-1 col-sm-1 col-md-1">letter_no: </label>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<?php
foreach($userdeatils->row() as $row): ?>
<input name="dakLetterNo" id="dakLetterNo" value="<?php echo $row['dakLetterNo'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<!-- <div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">created: </label>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="copy_to" id="copy_to" value="<?php //echo $userdeatils->created;?>"readonly="true" class="form-control" type="text" required />
</div> -->
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2 control-label">Attachment: </label>
<div class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<input type="file" name="Attachment" id="Attachment">
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Subject: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon" id="subjecterr"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="subject" id="Remark" value="<?php echo $row['Remark'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Place: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="place" id="place" value="<?php echo $row['place'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">from: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="from" id="receieve_add" value="<?php echo $row['receieve_add'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Created: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="created" id="created" value="<?php echo $row['created'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<!-- </div> -->
<!-- <div class="form-group"> -->
<!-- <label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Message: </label> -->
<!-- <div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10"> -->
<!-- <span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span> -->
<!-- <input name="message" id="message" value="<?php //echo $userdeatils->created;?>"readonly="true" class="form-control" type="text" required /> -->
<!-- </div> -->
<!-- </div> -->
<?php endforeach;?>
<div class="form-group">
<label class="col-lg-2 col-xs-12 col-sm-2 col-md-2">Message: </label>
<div class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<textarea class="form-control" id="message" name="message"></textarea>
<span id="messageerr" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 col-xs-12 col-sm-2 col-md-2">
Forward to
</label>
<div class="col-lg-6 col-xs-12 col-sm-6 col-md-6">
<select name="forwardto[]" id="agency" class="form-control">
<option value="">Select</option>
<?php
foreach($name as $row): ?>
<option value="<?php echo $row['cid']?>">
<?php echo $row['FirstName'].$row['MiddleName'].$row['LastName']?>
</option>
<?php endforeach;?>
</select>
<span id="forwarderr" class="text-danger"></span>
</div>
Model:
public function tracks($letterno="")
{
$query= $this->db->get_where('st_dak_details',array('dakLetterNo'=>$letterno));
if ($query->num_rows() > 0) {
return $query->row();
} else {
return array();
}
}
Controller:
function forwardtrack($param = '', $param2 = '') {
if (sizeof($this->db->get_where('st_forward', array('letter_no' => $param . '/' . $param2))->result_array()) > 0 && (!($param . '/' . $param2) )) {
$data1['message'] = 'notallow';
$this->load->view('track1', $data1);
} else {
$data1['name'] = $this->db->get_where('bpas_user_profiles', array('AgencyMainParentID' => $this->session->userdata('ministryId'), 'AgencyParentID' => $this->session->userdata('parentID'), 'AgencyID' => $this->session->userdata('agencyID')))->result_array();
$data1['userdeatils'] = $this->ag->tracks($param . '/' . $param2);
$this->load->view('userManagement/forward2', $data1);
}
/* ag=> agency model */
}
View:
<?php
if(!empty($userdeatils)){
foreach($userdeatils as $row) { ?>
//yout html code
...
...
<?php } ?>//foreach close
<?php } ?>//if close

Posting data over post route - Page expired

I'm attempting to post data to my database using Laravel, but I can't seem to do so. The post route sends to a an expired page.
Here is the route
Route::post('/expenses', 'PropertyExpenseController#store')->middleware('auth');
This is the create and store functions which render the form, and process the form.
public function create($id){
$property = PropertyAdvert::where('id', $id)->first();
return view('/pages/expenses/create', compact('property'));
}
public function store(Request $request){
$PropertyExpenses = PropertyExpenses::create([
"property_id" => $request->property_id,
"user_id" => Auth::user()->id,
"expenseDescription" => $request->description,
"cost" => $request->amount,
"date" => $request->date,
"category" => $request->category
]);
return "Expense Log";
}
This is the view page, where the form is loaded. All the data is got in the controller via the names on the input elements.
<form method="POST" action="/expenses">
<span name="property_id" class="text-muted">{{$property->id}}</span>
<div class="row mt-4 justify-content-center">
<div class="col-md-6">
<label class="" for"description">Expense Description<label>
</div>
</div>
<div class="row form-group justify-content-center">
<div class="col-md-4">
<input class="form-control " type="text" name="description">
</div>
</div>
<div class="row mt-4 justify-content-center">
<div class="col-md-6">
<label for"amount">Amount<label>
</div>
</div>
<div class="row form-group justify-content-center">
<div class="col-md-4 input-group">
<span class="input-group-addon mr-1 mt-1">€</span>
<input class="form-control" type="text" name="amount">
</div>
</div>
<div class="row mt-4 justify-content-center">
<div class="col-md-6">
<label for"category">Category<label>
</div>
</div>
<div class="row form-group justify-content-center">
<div class="col-md-4">
<select class="form-control" id="category" name="category">
<option>Mortgage Payment</option>
<option>Maintainence</option>
<option>Management Fee</option>
</select>
</div>
</div>
<div class="row mt-4 justify-content-center">
<div class="col-md-6">
<label for"description">Date<label>
</div>
</div>
<div class="row form-group justify-content-center">
<div class="col-md-4">
<input class="form-control" type="date" name="date">
</div>
</div>
<input type="submit" class="btn btn-primary" value="Log Expense">
</form>
THis is the model, with the fillable array.
class PropertyExpense extends Model
{
protected $fillable = ['property_id'. 'user_id', 'expenseDescription', 'cost', 'date', 'category'];
public function property(){
return $this->belongsTo('App\PropertyAdverts');
}
}
In your form, you need a CSRF Token field.
<input type="hidden" name="_token" value="{{ csrf_token() }}">
Read more here.

How to solve this error in laravel "Name and email address are required if not a client"

I'm getting an error as "Name and email address are required if not a client" while running the below mentioned code.
Find below the Controller Code:
class UserController extends Controller
{
public function insertform(){
return view('test');
}
public function create(){
$user=Whmcs::AddClient([
'firstname' => Input::get('firstname'),
'lastname' => Input::get('lastname'),
'email' => Input::get('email'),
'address1' => Input::get('address1'),
'city' => Input::get('city'),
'state' => Input::get('state'),
'postcode' => Input::get('postcode'),
'country' => Input::get('country'),
'phonenumber' => Input::get('phonenumber'),
'password2' => Input::get('password2'),
]);
return $user;
}
}
Find below the route code:
Route::get('insert', 'UserController#insertform');
Route::post('create', 'UserController#create')->name('user.create');
The blade file is given below
<div id="content" class="app-content" role="main">
<div class="app-content-body ">
<div class="bg-light lter b-b wrapper-md">
<h1 class="m-n font-thin h3">Sign up</h1>
</div>
<div class="wrapper-md" ng-controller="FormDemoCtrl">
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading font-bold">create an account</div>
<div class="panel-body">
<form class="bs-example form-horizontal" action="
{{route('user.create')}}" method="post">
<input type = "hidden" name = "_token" value = "<?php echo
csrf_token(); ?>">
<div class="form-group">
<label class="col-lg-2 control-label">firstname</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="firstname"
placeholder="Name">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">lastname</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="lastname"
placeholder="Name">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">Email</label>
<div class="col-lg-6">
<input type="email" class="form-control" name="email"
placeholder="Email">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">address1</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="address1"
placeholder="Subject">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">city</label>
<div class="col-lg-6">
<select class="form-control" name="city">
<option value="-- Select --">-- Select --</option>
<option value="Coimbatore">Coimbatore</option>
<option value="Chennai">Chennai</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">state</label>
<div class="col-lg-6">
<select class="form-control" name="state">
<option value="-- Select --">-- Select --</option>
<option value="Tamilnadu">Tamilnadu</option>
<option value="Andhra">Andhra</option>
<option value="Karnataka">Karnataka</option></select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">country</label>
<div class="col-lg-6">
<select class="form-control" name="country">
<option value="-- Select --">-- Select --</option>
<option value="India">India</option>
<option value="China">China</option>
<option value="Australia">Australia</option></select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">postcode</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="postcode"
placeholder="postcode">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">phonenumber</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="phonenumber"
placeholder="phonenumber">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">password</label>
<div class="col-lg-6">
<input type="password" class="form-control" name="password2"
placeholder="password">
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button type="submit" class="btn btn-sm btn-
success">Login</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
When I run the above code I'm getting an error as below:
{"result":"error","message":"Name and email address are required if not a client"}
suggest me a solution to solve this and post the data in laravel.

When Pass pdf file in ajax call then file_get_content() gives error

When i try to pass pdf at controller side through ajax at that time file_get_content() gives error like this
file_get_contents(): Filename cannot be empty
My output is like below:-
Illuminate\Http\UploadedFile Object(
[test:Symfony\Component\HttpFoundation\File\UploadedFile:private] =>
[originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 2017-playing-rules.pdf
[mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => application/octet-stream
[size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
[error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 1
[hashName:protected] =>
[pathName:SplFileInfo:private] =>
[fileName:SplFileInfo:private] =>
)
Here "[pathName:SplFileInfo:private]=>" gives null response which should have temp path of my uploaded file.
Here is my ajax call:-
$('#formAddLeague').on('success.form.bv', function(e) {
e.preventDefault();
var formData = new FormData(this);
$.ajax({
url:'{{ url('restoreleague') }}',
data:formData,
type:'post',
dataType:'json',
cache: false,
contentType: false,
processData: false,
success: function(data)
{
$('#loader').hide();
if(data.key == 1)
{
notify('League has been updated Successfully.','blackgloss');
}
}
});
});
In controller i used following:-
$import_rule = $request->file('importRule');
Here is my controller:-
public function restore(Request $request)
{
$league_id = $request->get('hiddenLeagueId');
$import_rule = $request->file('importRule');
$league_rule_url = $request->get('txtLeagueRule');
$objLeague = League::find($league_id);
if (!empty($import_rule)) {
$originalName = $import_rule->getClientOriginalName();
$ruleFileName = pathinfo($originalName, PATHINFO_FILENAME) . '.' . pathinfo($originalName, PATHINFO_EXTENSION);
$s3 = Storage::disk('s3');
$filePath = 'league_rules/' . $ruleFileName;
if ($s3->put($filePath, file_get_contents($import_rule) , 'public'))
{
$ruleURL = $s3->url($filePath);
$objLeague->league_rules = $ruleURL;
$objLeague->rules_filename = $ruleFileName;
}
}
else
if (!empty($league_rule_url))
{
$checkExtension = pathinfo($league_rule_url, PATHINFO_EXTENSION);
if ($checkExtension != 'pdf')
{
$msg = "The selected url extension is not valid.";
return $msg;
}
else
{
$objLeague->league_rules = $league_rule_url;
}
}
$objLeague->league_name = $request->get('txtLeagueName');
$objLeague->league_email = $request->get('txtLeagueEmail');
$objLeague->league_phone = $this->replacePhoneNumber($request->get('leagueContactNo'));
$objLeague->league_info = $request->get('txtLeagueInfo');
$objLeague->level_id = $request->get('txtLevel');
$objLeague->age_required = $request->get('txtMinRequiredAge');
$objLeague->league_website = $request->get('leagueWebsite');
$objLeague->save();
$response['key'] = 1;
return $response;
}
Here is my form:-
<div id="tab2" class="tab-pane">
<form id="formAddLeague" method="post">
{{ csrf_field() }}
<input id="hiddenLeagueId" type="hidden" name="hiddenLeagueId" value="{{$leagueDetail->league_id or ''}}">
<div class="row">
<div class="col-md-8">
<div class="form-group">
<label class="control-label"><b>LEAGUE NAME</b></label>
<input type="text" id="txtLeagueName" name="txtLeagueName" value="{{$leagueDetail->league_name or ''}}" class="form-control">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label"><b>LEAGUE ID</b></label><br>
<span class="disabled-color" id="leagueId">{{$leagueDetail->league_id or ''}}</span>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="control-label"><b>TYPE OF LEAGUE</b></label>
<select id="txtLevel" name="txtLevel" class="form-control">
<option value="">-- Select Type of League --</option>
#foreach($levelList as $level)
<option value="{{ $level->level_id }}" #if($leagueDetail->level_id == $level->level_id) {{"selected='selected'"}} #endif>{{ $level->level_name }}</option>
#endforeach
</select>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label"><b>MIN AGE REQUIREMENT</b></label>
<select id="txtMinRequiredAge" name="txtMinRequiredAge" class="form-control">
<option value="ALL AGES" #if($leagueDetail->age_required == 'ALL AGES') {{ "selected='selected'" }} #endif>All AGES</option>
<option value="18 AND OVER" #if($leagueDetail->age_required == '18 AND OVER') {{ "selected='selected'" }} #endif>18 AND OVER</option>
</select>
</div>
</div>
<div class="col-md-4">
<div class="form-group" style="overflow: visible!important;">
<label class="control-label"><b>SPORTS OFFERED</b></label>
<select id="txtLevel" name="txtLevel" class="form-control selectpicker" multiple data-style="form-control">
#foreach($levelList as $level)
<option value="{{ $level->level_id }}" #if($leagueDetail->level_id == $level->level_id) {{"selected='selected'"}} #endif>{{ $level->level_name }}</option>
#endforeach
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="control-label"><b>LEAGUE EMAIL</b></label>
<input style="text-transform: lowercase;" type="email" id="txtLeagueEmail" name="txtLeagueEmail" value="{{$leagueDetail->league_email or ''}}" class="form-control" placeholder="Enter Your Email">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label"><b>LEAGUE PHONE</b></label>
<input placeholder="(xxx) xxx-xxxx" type="text" name="leagueContactNo" id="leagueContactNo" value="{{$leagueDetail->league_phone or ''}}" class="form-control">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label"><b>LEAGUE WEBSITE</b></label>
<input id="leagueWebsite" type="text" name="leagueWebsite" value="{{$leagueDetail->league_website or ''}}" class="form-control" placeholder=" League website">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="control-label"><b>LEAGUE RULES</b></label>
<div class="row">
<div class="col-md-1">
<div class="radio radio-info">
<input type="radio" name="user_radio" id="file_radio" onclick="leagueRule(1)" checked>
<label> Use File </label>
</div>
</div>
<div class="col-md-11">
<div class="col-sm-12">
<div class="fileinput fileinput-new input-group" data-provides="fileinput">
<div class="form-control" data-trigger="fileinput">
<i class="glyphicon glyphicon-file fileinput-exists"></i>
<span class="fileinput-filename"></span>
</div>
<span class="input-group-addon btn btn-default btn-file">
<span class="fileinput-new"><i class="fa fa-upload"></i></span>
<span class="fileinput-exists">Change</span>
<input type="file" name="importRule" id="importRule">
</span>
Remove
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-1">
<div class="radio radio-info">
<input type="radio" name="user_radio" id="url_radio" onclick="leagueRule(2)">
<label> Use URL </label>
</div>
</div>
<div class="col-md-11">
<input disabled type="text" id="txtLeagueRule" name="txtLeagueRule" value="{{$leagueDetail->league_rules or '' }}" class="form-control" placeholder="Enter Link">
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group col-md-12 col-sm-12 col-xs-12">
<label class="control-label"><b>ABOUT</b></label>
<textarea id="txtLeagueInfo" style="resize: none;" class="form-control" rows="3" data-minwords="3" maxlength="238" name="txtLeagueInfo" placeholder="Type your message">{{$leagueDetail->league_info or ''}}</textarea>
<div id="textarea_feedback" style="text-align:right; color: red"></div>
{{-- <div id="textarea_feedback" class="text-left disabled-color"></div> --}}
</div>
</div>
</div>
<div class="form-group text-left p-t-md">
<button type="submit" class="btn btn-info">UPDATE</button>
</div>
</form>
</div>

codeigniter select list generated from database error when submitting the form

I have created a form which has 2 select box which also generate the options from database but the problem is when I do click on submit button the select box becomes empty.
here is the codes:
View:
<ol class="breadcrumb-icon">
<li><i class="fa fa-home"></i> Home</li>
<li class="active"><i class="icon fa fa-inbox"></i> Add Courses</li>
</ol>
<div class="page-header">
<h1>Add Courses:</h1>
</div>
<div class="well">
<?php if(isset($error)) echo $error;?>
<?php
$this->load->helper('form');
$attributes = array('role' => 'form','class'=>'form-horizontal');
echo form_open_multipart('admin/addcourses',$attributes);
?>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Course Category:</label>
<div class="col-sm-10">
<select name="category" class="form-control">
<?php
foreach ($cat as $row)
{
echo "<option value='".$row->category_id."'>".$row->category_name."</option>";
}
?>
</select>
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Course Location:</label>
<div class="col-sm-10">
<select name="location" class="form-control">
<?php
foreach ($loc as $row)
{
echo "<option value='".$row->location_id."'>".$row->location_name."</option>";
}
?>
</select>
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Course Language:</label>
<div class="col-sm-10">
<select name="language" class="form-control">
<option value="English">English</option>
<option value="Arabic">Arabic</option>
</select>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Course Name</label>
<div class="col-sm-10">
<input type="text" name="coursename" class="form-control" id="inputPassword3" placeholder="">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Course Date:</label>
<div class="col-sm-10">
<input type="text" name="date" id="range-picker" readonly class="form-control kd-daterange">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Course Image</label>
<div class="col-sm-10">
<input type="file" name="course_image" class="upload" readonly class="form-control kd-upload">
<p>keep it empty to use the default image.</p>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Add Course</button>
</div>
</div>
</form>
</div>
</div> <!-- /.container laaast -->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script src="js/extended.min.js"></script>
<script>
extended = new Extended();
</script>
Controller addcourses.php
public function addcourses()
{
if ($this->session->userdata('is_logged_in'))
{
$this->load->model('admin/read_cat_loc');
$data['cat']= $this->read_cat_loc->read_categories();
$data['loc']= $this->read_cat_loc->read_locations();
$this->load->view('admin/header_view');
$this->load->view('admin/addcourses_view',$data);
$this->load->view('admin/footer_view');
}
else {
redirect('admin/home');
}
}
model codes
class Read_cat_loc extends CI_Model {
public function read_categories() {
$query= $this->db->get('course_category');
return $query->result();
}
public function read_locations() {
$query= $this->db->get('course_location');
return $query->result();
}
}
ok solved:
I did this in main controller section :
$this->load->model('admin/read_cat_loc');
$data['cat']= $this->read_cat_loc->read_categories();
$data['loc']= $this->read_cat_loc->read_locations();
$this->load->view('admin/header_view');
$this->load->view('admin/addcourses_view',$data);
$this->load->view('admin/footer_view');
but in other areas where I have to reload the view I did this only:
$this->load->view('admin/header_view');
$this->load->view('admin/addcourses_view',$data);
$this->load->view('admin/footer_view');
without the model part to retain the data again ...
If you know better way It will be great. Thanks

Resources