I'm a newbie to PHP and Laravel. Last days i've been playing around and got some code doing what i wanted it to do. The point is that now i have some code in my controller, but i know i should make use of a model.
This is my controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class FixturesController extends Controller
{
/**
* Update fixtures
*
* @return db update all changed fixtures
*/
public function updateFixtures($comp_id)
{
$fixtarray = \Football::getLeagueFixtures($comp_id)['fixtures'];
foreach ($fixtarray as $key => $value){
$fixture = array_flatten($value);
$fixture_id = intval(substr($fixture[0], 41));
$competition = intval(substr($fixture[1], 45));
$homeTeam = intval(substr($fixture[2], 38));
$awayTeam = intval(substr($fixture[3], 38));
$date = date('d-m-Y H:i:s', strtotime($fixture[4]));
$status = $fixture[5];
$matchday = $fixture[6];
$homeTeamName = $fixture[7];
$awayTeamName = $fixture[8];
$goalsHomeTeam = $fixture[9];
$goalsAwayTeam = $fixture[10];
$dbvars = array("fixture_id", "competition", "homeTeam", "awayTeam", "date", "status", "matchday", "homeTeamName", "awayTeamName", "goalsHomeTeam", "goalsAwayTeam");
$finaldbvars = compact($dbvars);
\DB::table('fixtures')->where('fixture_id', $fixture_id)->update($finaldbvars);
echo "updated fixture for " . $fixture_id . "</br>";
}
}
}
Now when i run this, it does what i want, it updates the Database, but what would my project look like when i format and place it correctly?
I hope i'm in the right place with this question.
Thanks.
PS. I parse my array from an API
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire