What's the easiest way to transfer data from one table/Model to a different one for a beginner?
Apologies in advance for the huge wall of text, but I couldn't come up with a way to present my question in a shorter form because of the context-specific nature of it.
Please scroll down past the dotted line below if you'd like to skip my context intro:
I'm doing a coding challenge as my first Laravel application wherein I'm required to set up an attendance tracker/time tracker (Displaying how much time specific employees spent at work each day (Between a Check-In and Check-Out).
I'm a complete beginner (Going through Laravel 5.7 from Scratch On Laracasts Right now), so I'm looking for a solution/code approach that'd be within the scope of my current knowledge, and not something that I haven't learned on Laracasts yet.
Basically It'd be preferable for me to be pointed to a solution with syntax and methods that were shown until episode 20 on Laracasts (Basic Routing, Basic Controller usage, Basic Resource Controller usage, get & post, patch, delete methods, VERY BASIC eloquent relationships (Only know belongsTo & hasMany relationships).
Note that it's simply PREFERABLE to stick within these methods, but other solutions are more than welcome.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Summary of the situation is, I have an html table where I want to display the attendance statistics of Employees. I have an "Employee Management" page (/employees/manage view) where I can add new employees and save them in the "Current Employees" table.
Snippet from the /employees/manage view:
<div class="table_container">
<table class="table table-striped">
. . . . . . . . ..
@foreach($employees as $employee)
<tr>
<td>{{ $employee->id }}</td>
<td>{{ $employee->name }}</td>
<th>{{ $employee->position }}</th>
</tr>
@endforeach
</table>
</div>
code from the EmployeesController:
public function manage()
{
$employees = Employee::all();
return view('employees.manage', compact('employees'));
}
public function store()
{
$employee = new Employee();
$employee->name = request('name');
$employee->position = request('position');
$employee->save();
return redirect('/employees/manage');
}
I also have an "Attendance Management" page (/attendants/manage/ view), where I basically select available employees from a form type. I then plan to either "check in" or "check out" employees via respective buttons.
<option selected>Select an Employee</option>
@foreach($attendants as $attendant)
<option value="{{ $attendant->name }}">{{ $attendant->name }}</option>
@endforeach
How should I go about including available employees into the select form? I've been thinking about making an eloquent relationship between Employee and Attendant models:
class Attendant extends Model
{
public function employee()
{
return $this->belongsTo(Employee::class);
}
}
Here's the attendants migration:
{
Schema::create('attendants', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('employee_id');
$table->foreign('employee_id')->references('id')>on('employees');
. . . . .
$table->timestamps();
});
}
So, basically, my question is, how would I go about listing the available employees inside the select form?
Thanks in advance.
laravel eloquent
New contributor
add a comment |
Apologies in advance for the huge wall of text, but I couldn't come up with a way to present my question in a shorter form because of the context-specific nature of it.
Please scroll down past the dotted line below if you'd like to skip my context intro:
I'm doing a coding challenge as my first Laravel application wherein I'm required to set up an attendance tracker/time tracker (Displaying how much time specific employees spent at work each day (Between a Check-In and Check-Out).
I'm a complete beginner (Going through Laravel 5.7 from Scratch On Laracasts Right now), so I'm looking for a solution/code approach that'd be within the scope of my current knowledge, and not something that I haven't learned on Laracasts yet.
Basically It'd be preferable for me to be pointed to a solution with syntax and methods that were shown until episode 20 on Laracasts (Basic Routing, Basic Controller usage, Basic Resource Controller usage, get & post, patch, delete methods, VERY BASIC eloquent relationships (Only know belongsTo & hasMany relationships).
Note that it's simply PREFERABLE to stick within these methods, but other solutions are more than welcome.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Summary of the situation is, I have an html table where I want to display the attendance statistics of Employees. I have an "Employee Management" page (/employees/manage view) where I can add new employees and save them in the "Current Employees" table.
Snippet from the /employees/manage view:
<div class="table_container">
<table class="table table-striped">
. . . . . . . . ..
@foreach($employees as $employee)
<tr>
<td>{{ $employee->id }}</td>
<td>{{ $employee->name }}</td>
<th>{{ $employee->position }}</th>
</tr>
@endforeach
</table>
</div>
code from the EmployeesController:
public function manage()
{
$employees = Employee::all();
return view('employees.manage', compact('employees'));
}
public function store()
{
$employee = new Employee();
$employee->name = request('name');
$employee->position = request('position');
$employee->save();
return redirect('/employees/manage');
}
I also have an "Attendance Management" page (/attendants/manage/ view), where I basically select available employees from a form type. I then plan to either "check in" or "check out" employees via respective buttons.
<option selected>Select an Employee</option>
@foreach($attendants as $attendant)
<option value="{{ $attendant->name }}">{{ $attendant->name }}</option>
@endforeach
How should I go about including available employees into the select form? I've been thinking about making an eloquent relationship between Employee and Attendant models:
class Attendant extends Model
{
public function employee()
{
return $this->belongsTo(Employee::class);
}
}
Here's the attendants migration:
{
Schema::create('attendants', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('employee_id');
$table->foreign('employee_id')->references('id')>on('employees');
. . . . .
$table->timestamps();
});
}
So, basically, my question is, how would I go about listing the available employees inside the select form?
Thanks in advance.
laravel eloquent
New contributor
Actualy you dont need seperate tables for that. Just adding one status column easier i think. id - name - position - working_status If you must still work on seperate tables relationship will be good. if relationship does return instance that mean is this employe is working. If its not employee is available.This logic works too.
– Ali Özen
Jan 18 at 15:27
add a comment |
Apologies in advance for the huge wall of text, but I couldn't come up with a way to present my question in a shorter form because of the context-specific nature of it.
Please scroll down past the dotted line below if you'd like to skip my context intro:
I'm doing a coding challenge as my first Laravel application wherein I'm required to set up an attendance tracker/time tracker (Displaying how much time specific employees spent at work each day (Between a Check-In and Check-Out).
I'm a complete beginner (Going through Laravel 5.7 from Scratch On Laracasts Right now), so I'm looking for a solution/code approach that'd be within the scope of my current knowledge, and not something that I haven't learned on Laracasts yet.
Basically It'd be preferable for me to be pointed to a solution with syntax and methods that were shown until episode 20 on Laracasts (Basic Routing, Basic Controller usage, Basic Resource Controller usage, get & post, patch, delete methods, VERY BASIC eloquent relationships (Only know belongsTo & hasMany relationships).
Note that it's simply PREFERABLE to stick within these methods, but other solutions are more than welcome.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Summary of the situation is, I have an html table where I want to display the attendance statistics of Employees. I have an "Employee Management" page (/employees/manage view) where I can add new employees and save them in the "Current Employees" table.
Snippet from the /employees/manage view:
<div class="table_container">
<table class="table table-striped">
. . . . . . . . ..
@foreach($employees as $employee)
<tr>
<td>{{ $employee->id }}</td>
<td>{{ $employee->name }}</td>
<th>{{ $employee->position }}</th>
</tr>
@endforeach
</table>
</div>
code from the EmployeesController:
public function manage()
{
$employees = Employee::all();
return view('employees.manage', compact('employees'));
}
public function store()
{
$employee = new Employee();
$employee->name = request('name');
$employee->position = request('position');
$employee->save();
return redirect('/employees/manage');
}
I also have an "Attendance Management" page (/attendants/manage/ view), where I basically select available employees from a form type. I then plan to either "check in" or "check out" employees via respective buttons.
<option selected>Select an Employee</option>
@foreach($attendants as $attendant)
<option value="{{ $attendant->name }}">{{ $attendant->name }}</option>
@endforeach
How should I go about including available employees into the select form? I've been thinking about making an eloquent relationship between Employee and Attendant models:
class Attendant extends Model
{
public function employee()
{
return $this->belongsTo(Employee::class);
}
}
Here's the attendants migration:
{
Schema::create('attendants', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('employee_id');
$table->foreign('employee_id')->references('id')>on('employees');
. . . . .
$table->timestamps();
});
}
So, basically, my question is, how would I go about listing the available employees inside the select form?
Thanks in advance.
laravel eloquent
New contributor
Apologies in advance for the huge wall of text, but I couldn't come up with a way to present my question in a shorter form because of the context-specific nature of it.
Please scroll down past the dotted line below if you'd like to skip my context intro:
I'm doing a coding challenge as my first Laravel application wherein I'm required to set up an attendance tracker/time tracker (Displaying how much time specific employees spent at work each day (Between a Check-In and Check-Out).
I'm a complete beginner (Going through Laravel 5.7 from Scratch On Laracasts Right now), so I'm looking for a solution/code approach that'd be within the scope of my current knowledge, and not something that I haven't learned on Laracasts yet.
Basically It'd be preferable for me to be pointed to a solution with syntax and methods that were shown until episode 20 on Laracasts (Basic Routing, Basic Controller usage, Basic Resource Controller usage, get & post, patch, delete methods, VERY BASIC eloquent relationships (Only know belongsTo & hasMany relationships).
Note that it's simply PREFERABLE to stick within these methods, but other solutions are more than welcome.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Summary of the situation is, I have an html table where I want to display the attendance statistics of Employees. I have an "Employee Management" page (/employees/manage view) where I can add new employees and save them in the "Current Employees" table.
Snippet from the /employees/manage view:
<div class="table_container">
<table class="table table-striped">
. . . . . . . . ..
@foreach($employees as $employee)
<tr>
<td>{{ $employee->id }}</td>
<td>{{ $employee->name }}</td>
<th>{{ $employee->position }}</th>
</tr>
@endforeach
</table>
</div>
code from the EmployeesController:
public function manage()
{
$employees = Employee::all();
return view('employees.manage', compact('employees'));
}
public function store()
{
$employee = new Employee();
$employee->name = request('name');
$employee->position = request('position');
$employee->save();
return redirect('/employees/manage');
}
I also have an "Attendance Management" page (/attendants/manage/ view), where I basically select available employees from a form type. I then plan to either "check in" or "check out" employees via respective buttons.
<option selected>Select an Employee</option>
@foreach($attendants as $attendant)
<option value="{{ $attendant->name }}">{{ $attendant->name }}</option>
@endforeach
How should I go about including available employees into the select form? I've been thinking about making an eloquent relationship between Employee and Attendant models:
class Attendant extends Model
{
public function employee()
{
return $this->belongsTo(Employee::class);
}
}
Here's the attendants migration:
{
Schema::create('attendants', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('employee_id');
$table->foreign('employee_id')->references('id')>on('employees');
. . . . .
$table->timestamps();
});
}
So, basically, my question is, how would I go about listing the available employees inside the select form?
Thanks in advance.
laravel eloquent
laravel eloquent
New contributor
New contributor
edited Jan 18 at 17:47
Yves Kipondo
1,373414
1,373414
New contributor
asked Jan 18 at 14:10
GiorgiMGGiorgiMG
11
11
New contributor
New contributor
Actualy you dont need seperate tables for that. Just adding one status column easier i think. id - name - position - working_status If you must still work on seperate tables relationship will be good. if relationship does return instance that mean is this employe is working. If its not employee is available.This logic works too.
– Ali Özen
Jan 18 at 15:27
add a comment |
Actualy you dont need seperate tables for that. Just adding one status column easier i think. id - name - position - working_status If you must still work on seperate tables relationship will be good. if relationship does return instance that mean is this employe is working. If its not employee is available.This logic works too.
– Ali Özen
Jan 18 at 15:27
Actualy you dont need seperate tables for that. Just adding one status column easier i think. id - name - position - working_status If you must still work on seperate tables relationship will be good. if relationship does return instance that mean is this employe is working. If its not employee is available.This logic works too.
– Ali Özen
Jan 18 at 15:27
Actualy you dont need seperate tables for that. Just adding one status column easier i think. id - name - position - working_status If you must still work on seperate tables relationship will be good. if relationship does return instance that mean is this employe is working. If its not employee is available.This logic works too.
– Ali Özen
Jan 18 at 15:27
add a comment |
1 Answer
1
active
oldest
votes
/employees/manage view listing : fine
EmployeesController
public function store(Request $request)
{
// Use validation
Employee::create($request->all());
return redirect()->route(employees.manage); //Try to use route
}
for HTML Form use Laravel Collective it will reduce your code. after adding laravel form collective
{!! Form::select('attendants', $attendants, $selected_val,['id'=>'id','class'=>'class']) !!}
One line code for select box and options
use Validation
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
GiorgiMG is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54255711%2fwhats-the-easiest-way-to-transfer-data-from-one-table-model-to-a-different-one%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
/employees/manage view listing : fine
EmployeesController
public function store(Request $request)
{
// Use validation
Employee::create($request->all());
return redirect()->route(employees.manage); //Try to use route
}
for HTML Form use Laravel Collective it will reduce your code. after adding laravel form collective
{!! Form::select('attendants', $attendants, $selected_val,['id'=>'id','class'=>'class']) !!}
One line code for select box and options
use Validation
add a comment |
/employees/manage view listing : fine
EmployeesController
public function store(Request $request)
{
// Use validation
Employee::create($request->all());
return redirect()->route(employees.manage); //Try to use route
}
for HTML Form use Laravel Collective it will reduce your code. after adding laravel form collective
{!! Form::select('attendants', $attendants, $selected_val,['id'=>'id','class'=>'class']) !!}
One line code for select box and options
use Validation
add a comment |
/employees/manage view listing : fine
EmployeesController
public function store(Request $request)
{
// Use validation
Employee::create($request->all());
return redirect()->route(employees.manage); //Try to use route
}
for HTML Form use Laravel Collective it will reduce your code. after adding laravel form collective
{!! Form::select('attendants', $attendants, $selected_val,['id'=>'id','class'=>'class']) !!}
One line code for select box and options
use Validation
/employees/manage view listing : fine
EmployeesController
public function store(Request $request)
{
// Use validation
Employee::create($request->all());
return redirect()->route(employees.manage); //Try to use route
}
for HTML Form use Laravel Collective it will reduce your code. after adding laravel form collective
{!! Form::select('attendants', $attendants, $selected_val,['id'=>'id','class'=>'class']) !!}
One line code for select box and options
use Validation
answered Jan 18 at 17:05
bhavinjrbhavinjr
134
134
add a comment |
add a comment |
GiorgiMG is a new contributor. Be nice, and check out our Code of Conduct.
GiorgiMG is a new contributor. Be nice, and check out our Code of Conduct.
GiorgiMG is a new contributor. Be nice, and check out our Code of Conduct.
GiorgiMG is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54255711%2fwhats-the-easiest-way-to-transfer-data-from-one-table-model-to-a-different-one%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Actualy you dont need seperate tables for that. Just adding one status column easier i think. id - name - position - working_status If you must still work on seperate tables relationship will be good. if relationship does return instance that mean is this employe is working. If its not employee is available.This logic works too.
– Ali Özen
Jan 18 at 15:27