mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 14:31:26 +00:00
Add Place model
This commit is contained in:
parent
1ee80a281b
commit
3ed275df31
3 changed files with 101 additions and 0 deletions
23
app/Http/Controllers/PlaceController.php
Normal file
23
app/Http/Controllers/PlaceController.php
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\{
|
||||||
|
Place,
|
||||||
|
Status
|
||||||
|
};
|
||||||
|
|
||||||
|
class PlaceController extends Controller
|
||||||
|
{
|
||||||
|
public function show(Request $request, $id, $slug)
|
||||||
|
{
|
||||||
|
// TODO: Replace with vue component + apis
|
||||||
|
$place = Place::whereSlug($slug)->findOrFail($id);
|
||||||
|
$posts = Status::wherePlaceId($place->id)
|
||||||
|
->whereScope('public')
|
||||||
|
->orderByDesc('created_at')
|
||||||
|
->paginate(10);
|
||||||
|
return view('discover.places.show', compact('place', 'posts'));
|
||||||
|
}
|
||||||
|
}
|
33
app/Place.php
Normal file
33
app/Place.php
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Pixelfed\Snowflake\HasSnowflakePrimary;
|
||||||
|
|
||||||
|
class Place extends Model
|
||||||
|
{
|
||||||
|
use HasSnowflakePrimary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the IDs are auto-incrementing.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $incrementing = false;
|
||||||
|
|
||||||
|
public function url()
|
||||||
|
{
|
||||||
|
return url('/discover/places/' . $this->id . '/' . $this->slug);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function posts()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Status::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postCount()
|
||||||
|
{
|
||||||
|
return $this->posts()->count();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class CreatePlacesTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('places', function (Blueprint $table) {
|
||||||
|
$table->bigIncrements('id');
|
||||||
|
$table->string('slug')->index();
|
||||||
|
$table->string('name')->index();
|
||||||
|
$table->string('country')->index();
|
||||||
|
$table->json('aliases')->nullable();
|
||||||
|
$table->decimal('lat', 9, 6)->nullable();
|
||||||
|
$table->decimal('long', 9, 6)->nullable();
|
||||||
|
$table->unique(['slug', 'country', 'lat', 'long']);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('statuses', function (Blueprint $table) {
|
||||||
|
$table->bigInteger('place_id')->unsigned()->nullable()->index();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('places');
|
||||||
|
Schema::table('statuses', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('place_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue