mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 03:04:05 +00:00
133 - Storing Messages for Attendees
This commit is contained in:
10
app/AttendeeMessage.php
Normal file
10
app/AttendeeMessage.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class AttendeeMessage extends Model
|
||||||
|
{
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
||||||
@@ -15,6 +15,11 @@ class Concert extends Model
|
|||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function attendeeMessages()
|
||||||
|
{
|
||||||
|
return $this->hasMany(AttendeeMessage::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function scopePublished($query)
|
public function scopePublished($query)
|
||||||
{
|
{
|
||||||
return $query->whereNotNull('published_at');
|
return $query->whereNotNull('published_at');
|
||||||
|
|||||||
@@ -14,4 +14,14 @@ class ConcertMessagesController extends Controller
|
|||||||
|
|
||||||
return view('backstage.concert-messages.new', ['concert' => $concert]);
|
return view('backstage.concert-messages.new', ['concert' => $concert]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function store($id)
|
||||||
|
{
|
||||||
|
$concert = Auth::user()->concerts()->findOrFail($id);
|
||||||
|
|
||||||
|
$message = $concert->attendeeMessages()->create(request(['subject', 'message']));
|
||||||
|
|
||||||
|
return redirect()->route('backstage.concert-messages.new', $concert)
|
||||||
|
->with('flash', "Your message has been sent.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class CreateAttendeeMessagesTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('attendee_messages', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->unsignedInteger('concert_id');
|
||||||
|
$table->string('subject');
|
||||||
|
$table->text('message');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('attendee_messages');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,5 +30,6 @@ Route::group(['middleware' => 'auth', 'prefix' => 'backstage', 'namespace' => 'B
|
|||||||
Route::get('/published-concerts/{id}/orders', 'PublishedConcertOrdersController@index')->name('backstage.published-concert-orders.index');
|
Route::get('/published-concerts/{id}/orders', 'PublishedConcertOrdersController@index')->name('backstage.published-concert-orders.index');
|
||||||
|
|
||||||
Route::get('/concerts/{id}/messages/new', 'ConcertMessagesController@create')->name('backstage.concert-messages.new');
|
Route::get('/concerts/{id}/messages/new', 'ConcertMessagesController@create')->name('backstage.concert-messages.new');
|
||||||
|
Route::post('/concerts/{id}/messages', 'ConcertMessagesController@store')->name('backstage.concert-messages.store');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace Tests\Feature\Backstage;
|
|||||||
use App\User;
|
use App\User;
|
||||||
use ConcertFactory;
|
use ConcertFactory;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
use App\AttendeeMessage;
|
||||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||||
|
|
||||||
class MessageAttendeesTest extends TestCase
|
class MessageAttendeesTest extends TestCase
|
||||||
@@ -50,4 +51,28 @@ class MessageAttendeesTest extends TestCase
|
|||||||
|
|
||||||
$response->assertRedirect('/login');
|
$response->assertRedirect('/login');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
function a_promoter_can_send_a_new_message()
|
||||||
|
{
|
||||||
|
$this->disableExceptionHandling();
|
||||||
|
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
$concert = ConcertFactory::createPublished([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->post("/backstage/concerts/{$concert->id}/messages", [
|
||||||
|
'subject' => 'My subject',
|
||||||
|
'message' => 'My message',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertRedirect("/backstage/concerts/{$concert->id}/messages/new");
|
||||||
|
$response->assertSessionHas('flash');
|
||||||
|
|
||||||
|
$message = AttendeeMessage::first();
|
||||||
|
$this->assertEquals($concert->id, $message->concert_id);
|
||||||
|
$this->assertEquals('My subject', $message->subject);
|
||||||
|
$this->assertEquals('My message', $message->message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user