-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Application With Travel Photos
- Loading branch information
erika
committed
Oct 15, 2019
1 parent
4138191
commit 10b6cdd
Showing
19 changed files
with
305 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Place; | ||
use App\Photo; | ||
|
||
class MainController extends Controller | ||
{ | ||
public function main() | ||
{ | ||
|
||
$visited = Place::where('visited', 1)->get(); | ||
$togo = Place::where('visited', 0)->get(); | ||
|
||
$photos = Photo::all(); | ||
|
||
return view('travel_list', [ | ||
'visited' => $visited, | ||
'togo' => $togo, | ||
'photos' => $photos | ||
]); | ||
} | ||
|
||
public function uploadForm() | ||
{ | ||
$places = Place::all(); | ||
|
||
return view('upload_photo', [ | ||
'places' => $places | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Photo; | ||
use App\Place; | ||
|
||
class PhotoController extends Controller | ||
{ | ||
public function uploadPhoto(Request $request) | ||
{ | ||
$photo = new Photo(); | ||
$place = Place::find($request->input('place')); | ||
|
||
if (!$place) { | ||
//add new place | ||
$place = new Place(); | ||
$place->name = $request->input('place_name'); | ||
$place->lat = $request->input('place_lat'); | ||
$place->lng = $request->input('place_lng'); | ||
} | ||
|
||
$place->visited = 1; | ||
$place->save(); | ||
|
||
$photo->place()->associate($place); | ||
$photo->image = $request->image->store('photos', 'public'); | ||
$photo->save(); | ||
|
||
return redirect()->route('Main'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Photo extends Model | ||
{ | ||
public function place() | ||
{ | ||
return $this->belongsTo('App\Place'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,8 @@ | |
|
||
class Place extends Model | ||
{ | ||
// | ||
public function photos() | ||
{ | ||
return $this->hasMany('App\Photo'); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
database/migrations/2019_10_14_124700_create_photos_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreatePhotosTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('photos', function (Blueprint $table) { | ||
$table->bigIncrements('id'); | ||
$table->unsignedBigInteger('place_id'); | ||
$table->string('image'); | ||
$table->foreign('place_id')->references('id')->on('places'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('photos'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
function add_map_point(lat, lng, icon) { | ||
var vectorLayer = new ol.layer.Vector({ | ||
source:new ol.source.Vector({ | ||
features: [new ol.Feature({ | ||
geometry: new ol.geom.Point(ol.proj.transform([parseFloat(lng), parseFloat(lat)], 'EPSG:4326', 'EPSG:3857')), | ||
})] | ||
}), | ||
style: new ol.style.Style({ | ||
image: new ol.style.Icon({ | ||
anchor: [0.5, 1], | ||
anchorXUnits: "fraction", | ||
anchorYUnits: "fraction", | ||
src: icon | ||
}) | ||
}) | ||
}); | ||
map.addLayer(vectorLayer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="/css/global.css" type="text/css"> | ||
<link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" type="text/css"> | ||
<link href="https://fonts.googleapis.com/css?family=Anton&display=swap" rel="stylesheet"> | ||
<link href="https://fonts.googleapis.com/css?family=Hind&display=swap" rel="stylesheet"> | ||
|
||
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script> | ||
<script src="/js/map.js"></script> | ||
|
||
<title>Sammy's Travels</title> | ||
</head> | ||
|
||
<body class="container"> | ||
|
||
<header> | ||
<h1>Sammy's Travels</h1> | ||
</header> | ||
|
||
<div class="main"> | ||
@yield('content') | ||
</div> | ||
|
||
<div class="footer clearfix"> | ||
@yield('footer') | ||
</div> | ||
|
||
|
||
@yield('script') | ||
|
||
|
||
</body> | ||
</html> |
Oops, something went wrong.